--- src/softmagic.c.orig 2009-03-09 18:47:28.000000000 -0700 +++ src/softmagic.c 2009-03-09 18:48:17.000000000 -0700 @@ -338,12 +338,12 @@ size_t len; char *copy; - len = strlen(str); - if (len > n) - len = n; - if (!(copy = malloc(len + 1))) + for (len = 0; len < n && str[len]; len++) + continue; + + if ((copy = malloc(len + 1)) == NULL) return (NULL); - (void) memcpy(copy, str, len + 1); + memcpy(copy, str, len); copy[len] = '\0'; return (copy); }