]> git.ipfire.org Git - thirdparty/shadow.git/commit
lib/string/: Redesign stpecpy() and stpeprintf()
authorAlejandro Colomar <alx@kernel.org>
Sat, 8 Feb 2025 13:41:16 +0000 (14:41 +0100)
committerAlejandro Colomar <foss+github@alejandro-colomar.es>
Fri, 15 May 2026 10:06:49 +0000 (12:06 +0200)
commit76aa80744e848a50ea6790fed151a61733ffda76
treeec0d308feb7165255931f47c5ad7655465ed7257
parent4ed0e0ca8d7578e4631459a5724a9a27ad0b9b54
lib/string/: Redesign stpecpy() and stpeprintf()

Make them report truncation via errno and NULL.

Instead of having three possible returns (a pointer to the NUL byte, the
end of the array, or NULL), reduce it to two possible ones: one for
success, and one for error.

Use errno, which is a common way to signal the specific error, and thus
treat truncation as any other error.  This simplifies error handling
after these calls.  Also, if one misuses a pointer after truncation, the
results are better if the pointer is NULL: the program will easily
abort.  If we returned 'end', the program could more easily produce a
buffer overrun.

Suggested-by: Douglas McIlroy <douglas.mcilroy@dartmouth.edu>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/string/sprintf/stpeprintf.h
lib/string/strcpy/stpecpy.h