diff options
| author | The Android Open Source Project <initial-contribution@android.com> | 2010-05-12 09:22:50 -0700 |
|---|---|---|
| committer | The Android Open Source Project <initial-contribution@android.com> | 2010-05-12 09:22:50 -0700 |
| commit | bb7928ccdae0cc5766f290e18ab14b07d80c6912 (patch) | |
| tree | 76468dcde3da9d42bdc3a2146463583e65593205 /libc/string/strndup.c | |
| parent | f450fa5f991af3c0814f96265cb3b2aafdce2309 (diff) | |
| parent | c3581dc78a51180d3550d0d04596657cb2db852c (diff) | |
| download | bionic-bb7928ccdae0cc5766f290e18ab14b07d80c6912.zip bionic-bb7928ccdae0cc5766f290e18ab14b07d80c6912.tar.gz bionic-bb7928ccdae0cc5766f290e18ab14b07d80c6912.tar.bz2 | |
merge from open-source master
Change-Id: Iecfd2bd3069f70bbe508042cc249fcf7ff24800d
Diffstat (limited to 'libc/string/strndup.c')
| -rw-r--r-- | libc/string/strndup.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/libc/string/strndup.c b/libc/string/strndup.c index da9a55f..9dca79c 100644 --- a/libc/string/strndup.c +++ b/libc/string/strndup.c @@ -31,12 +31,14 @@ char* strndup(const char* s, size_t n) { size_t slen = (size_t)strlen(s); - int len = slen < n ? slen : n; - char* copy = malloc(len+1); + char* copy; + if (slen < n) + n = slen; + copy = malloc(n+1); if (copy) { - memcpy( copy, s, len ); - copy[len] = 0; + memcpy(copy, s, n); + copy[n] = 0; } return copy; } |
