Merge pull request #6 from CindyLinz/master
my_strdup / my_strndup malloc smaller
This commit is contained in:
commit
6c0b3c3e90
1 changed files with 2 additions and 2 deletions
|
@ -188,7 +188,7 @@ char *strdup(const char *s) {
|
||||||
while( s[count] )
|
while( s[count] )
|
||||||
++count;
|
++count;
|
||||||
++count;
|
++count;
|
||||||
out = malloc(sizeof(char*) * count);
|
out = malloc(sizeof(char) * count);
|
||||||
out[--count] = 0;
|
out[--count] = 0;
|
||||||
while( --count >= 0 )
|
while( --count >= 0 )
|
||||||
out[count] = s[count];
|
out[count] = s[count];
|
||||||
|
@ -203,7 +203,7 @@ char *strndup(const char *s, int n) {
|
||||||
while( count < n && s[count] )
|
while( count < n && s[count] )
|
||||||
++count;
|
++count;
|
||||||
++count;
|
++count;
|
||||||
out = malloc(sizeof(char*) * count);
|
out = malloc(sizeof(char) * count);
|
||||||
out[--count] = 0;
|
out[--count] = 0;
|
||||||
while( --count >= 0 )
|
while( --count >= 0 )
|
||||||
out[count] = s[count];
|
out[count] = s[count];
|
||||||
|
|
Loading…
Reference in a new issue