diff options
author | David Turner <digit@android.com> | 2010-05-10 14:52:02 -0700 |
---|---|---|
committer | Android Code Review <code-review@android.com> | 2010-05-10 14:52:02 -0700 |
commit | d791da79432064bc954fedf8d4e4394aaafefe75 (patch) | |
tree | 6d731e33e6d3f2ff28feff74ef07cc680aee886e | |
parent | 0be7eda75a14815aaa3e5cd5d5d4e5d25dc35d1c (diff) | |
parent | aba3ee7d322f30735433e2e6ae98fa3d849a1c7e (diff) | |
download | bionic-d791da79432064bc954fedf8d4e4394aaafefe75.zip bionic-d791da79432064bc954fedf8d4e4394aaafefe75.tar.gz bionic-d791da79432064bc954fedf8d4e4394aaafefe75.tar.bz2 |
Merge "string: tidy up strndup()"
-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; } |