diff --git a/src/readelf.c b/src/readelf.c
index fed85efe..5c557522 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -1827,7 +1827,7 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
 				continue;
 			if (bufsize && nbuf[0]) {
 				nbuf[bufsize - 1] = '\0';
-				memcpy(interp, nbuf, CAST(size_t, bufsize));
+				strlcpy(interp, RCAST(char *, nbuf), sizeof(interp));
 			} else
 				strlcpy(interp, "*empty*", sizeof(interp));
 			break;
