From: Alejandro Colomar Date: Mon, 21 Jul 2025 14:56:34 +0000 (+0200) Subject: lib/string/strcpy/: stpecpy(): Use strtcpy() instead of its pattern X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=16cac2114bc71760c8933590113f31332cbb7ee1;p=thirdparty%2Fshadow.git lib/string/strcpy/: stpecpy(): Use strtcpy() instead of its pattern Signed-off-by: Alejandro Colomar --- diff --git a/lib/string/strcpy/stpecpy.h b/lib/string/strcpy/stpecpy.h index c46346b8f..c2471d4da 100644 --- a/lib/string/strcpy/stpecpy.h +++ b/lib/string/strcpy/stpecpy.h @@ -14,6 +14,7 @@ #include #include "attr.h" +#include "string/strcpy/strtcpy.h" #if !defined(HAVE_STPECPY) @@ -27,25 +28,16 @@ inline char *stpecpy(char *dst, const char *end, const char *restrict src); inline char * stpecpy(char *dst, const char *end, const char *restrict src) { - bool trunc; - char *p; - size_t dsize, dlen, slen; + ssize_t dlen; if (dst == NULL) return NULL; - dsize = end - dst; - slen = strnlen(src, dsize); - trunc = (slen == dsize); - dlen = slen - trunc; - - p = stpcpy(mempcpy(dst, src, dlen), ""); - if (trunc) { - errno = E2BIG; + dlen = strtcpy(dst, src, end - dst); + if (dlen == -1) return NULL; - } - return p; + return dst + dlen; } #endif