summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2009-05-11 13:44:30 (GMT)
committer John Mark Bell <jmb@netsurf-browser.org>2009-05-11 13:44:30 (GMT)
commit9d36bd3bbc553fcbabe7c69811e996876f539f43 (patch)
treeb4325557683a38ffa6672a7f8d817c21991d9029
parentd786ebb77edb5384f2a0fd679ee3f248717a337c (diff)
downloadttf2f-9d36bd3bbc553fcbabe7c69811e996876f539f43.tar.gz
ttf2f-9d36bd3bbc553fcbabe7c69811e996876f539f43.tar.bz2
Make strndup implementation more robust
svn path=/trunk/tools/ttf2f/; revision=7464
-rw-r--r--src/utils.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/utils.c b/src/utils.c
index 1aea66f..9698825 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -6,21 +6,18 @@
char *strndup(const char *s, size_t n)
{
- /* this assumes s is NUL terminated - if not,
- * some silly value will be returned */
- size_t len = strlen(s);
+ size_t len = 0;
char *res;
- /* limit to n */
- if (len > n || n == 0)
- len = n;
+ while (len < n && s[len] != '\0')
+ len++;
- res = (char *) malloc(len + 1);
+ res = malloc(len + 1);
if (res == NULL)
return NULL;
res[len] = '\0';
- return (char *) memcpy(res, s, len);
+ return memcpy(res, s, len);
}
/**