This is an archive of the discontinued LLVM Phabricator instance.

[libc] Add strncat and fix strcat
ClosedPublic

Authored by michaelrj on Oct 11 2021, 3:50 PM.

Details

Summary

This adds strncat to llvm libc. In addition, an error was found with
strcat and that was fixed.

Diff Detail

Event Timeline

michaelrj created this revision.Oct 11 2021, 3:50 PM
michaelrj requested review of this revision.Oct 11 2021, 3:50 PM
lntue added inline comments.Oct 11 2021, 9:47 PM
libc/src/string/strncat.cpp
23

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.

libc/test/src/string/strncat_test.cpp
61

Nit: Also add tests where count = srcLength + 1 and count > srcLength + 1.

michaelrj marked 2 inline comments as done.

fix strncat writing null bytes beyond the end of src, and add a test for that.

michaelrj edited the summary of this revision. (Show Details)Oct 12 2021, 10:00 AM
lntue accepted this revision.Oct 12 2021, 10:58 AM
This revision is now accepted and ready to land.Oct 12 2021, 10:58 AM
This revision was automatically updated to reflect the committed changes.
sivachandra added inline comments.
libc/src/string/strcat.cpp
22

Its not clear to me as to what this change has done that something got "fixed". A corresponding test would have helped me see it may be.