my_strdup / my_strndup malloc smaller
This commit is contained in:
parent
1f91b8ea35
commit
1c9a42dd82
1 changed files with 2 additions and 2 deletions
|
@ -187,7 +187,7 @@ char *my_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];
|
||||||
|
@ -200,7 +200,7 @@ char *my_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