]> granicus.if.org Git - yasm/commitdiff
Fix issue with [1843]; we can't use strlen() here as we can be given
authorPeter Johnson <peter@tortall.net>
Sun, 20 May 2007 19:50:04 +0000 (19:50 -0000)
committerPeter Johnson <peter@tortall.net>
Sun, 20 May 2007 19:50:04 +0000 (19:50 -0000)
an unterminated input string.

svn path=/trunk/yasm/; revision=1849

libyasm/xstrdup.c

index 54af2fae19ec1d54def4db7a58667a1fa7ce8f95..83ac3955de2c90ee452e928f0611209f85ae8e83 100644 (file)
@@ -58,12 +58,11 @@ yasm__xstrdup(const char *str)
 char *
 yasm__xstrndup(const char *str, size_t max)
 {
-        size_t len;
+        size_t len = 0;
         char *copy;
 
-        len = strlen(str);
-        if (len > max)
-            len = max;
+        while (len < max && str[len] != '\0')
+            len++;
         copy = yasm_xmalloc(len+1);
         memcpy(copy, str, len);
         copy[len] = '\0';