HomePhabricator

Add few docs and implementation of strcpy and strcat.

Description

Add few docs and implementation of strcpy and strcat.

Summary:
This patch illustrates some of the features like modularity we want
in the new libc. Few other ideas like different kinds of testing, redirectors
etc are not yet present.

Reviewers: dlj, hfinkel, theraven, jfb, alexshap, jdoerfert

Subscribers: mgorny, dexonsmith, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D67867

Details

Committed
sivachandraOct 4 2019, 10:30 AM
Differential Revision
D67867: [libc] Add few docs and implementation of strcpy and strcat.
Parents
rL373763: [Automaton] Fix invalid iterator reference
Branches
Unknown
Tags
Unknown

Event Timeline

nelhage marked 2 inline comments as done.Oct 7 2019, 2:26 PM
nelhage added a subscriber: nelhage.

I was skimming this on a pointer from http://llvmweekly.org/ and noticed two issues in the tests. Excited to see the LLVM libc project kicking off!

/libc/trunk/src/string/strcat/strcat_test.cpp
30

This is a heap buffer overflow -- strcat will write off the end of the 4-byte allocation when we append "abc\0" to "xyz\0". The size here should be changed to at least 7, but more importantly, this is probably a strong argument for landing sanitized tests early :)

42

googletest's ASSERT_* macros desugar into something that returns on failure and so tests written in this style will leak memory (and thus eventually trigger sanitizer errors) on failure.

unique_ptr or just a stack allocation should work fine here and avoid that pitfall.

alex added a subscriber: alex.Oct 7 2019, 2:33 PM

This kind of tests (tests in an environment with a libc) work for pure functions in math.h, ctype.h, search.h, stdlib.h, string.h, and probably some other header files, but not for many others. I don't think pure functions are majority in libc and POSIX functions. For consistency, a different testing scheme is needed.