[libc-commits] [PATCH] D111583: [libc] Add strncat and fix strcat
Tue Ly via Phabricator via libc-commits
libc-commits at lists.llvm.org
Mon Oct 11 21:47:14 PDT 2021
lntue added inline comments.
================
Comment at: libc/src/string/strncat.cpp:23
+ size_t destLength = internal::string_length(dest);
+ __llvm_libc::strncpy(dest + destLength, src, count);
+ dest[destLength + copyAmount] = '\0';
----------------
I think you should use `copyAmount` here instead of `count`, since for strncpy it is specifically said that when srcLength < count, extra '\0' 's will be appended upto `count`. On the other hand, strncat is only specified to be null-terminated.
================
Comment at: libc/test/src/string/strncat_test.cpp:60
+
+ result = __llvm_libc::strncat(dest, abc, 3);
+ ASSERT_EQ(dest, result);
----------------
Nit: Also add tests where count = srcLength + 1 and count > srcLength + 1.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D111583/new/
https://reviews.llvm.org/D111583
More information about the libc-commits
mailing list