my_strdup / my_strndup malloc smaller

This commit is contained in:
Cindy Wang (CindyLinz) 2014-05-17 13:01:33 +08:00
parent 1f91b8ea35
commit 1c9a42dd82

View file

@ -187,7 +187,7 @@ char *my_strdup(const char *s) {
while( s[count] )
++count;
++count;
out = malloc(sizeof(char*) * count);
out = malloc(sizeof(char) * count);
out[--count] = 0;
while( --count >= 0 )
out[count] = s[count];
@ -200,7 +200,7 @@ char *my_strndup(const char *s, int n) {
while( count < n && s[count] )
++count;
++count;
out = malloc(sizeof(char*) * count);
out = malloc(sizeof(char) * count);
out[--count] = 0;
while( --count >= 0 )
out[count] = s[count];