From: Alejandro Colomar Date: Sat, 8 Feb 2025 15:19:02 +0000 (+0100) Subject: lib/string/sprintf/: snprintf_(): Use ssize_t instead of size_t in $2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ef4334379a6c8d9a200f0d4ea3f403f379484df9;p=thirdparty%2Fshadow.git lib/string/sprintf/: snprintf_(): Use ssize_t instead of size_t in $2 vsnprintf(3) returns an int. By using ssize_t, which is also signed, we avoid the need for a cast. Cc: Serge Hallyn Signed-off-by: Alejandro Colomar --- diff --git a/lib/string/sprintf/snprintf.c b/lib/string/sprintf/snprintf.c index e3755da76..f4ede2596 100644 --- a/lib/string/sprintf/snprintf.c +++ b/lib/string/sprintf/snprintf.c @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar +// SPDX-FileCopyrightText: 2023-2025, Alejandro Colomar // SPDX-License-Identifier: BSD-3-Clause @@ -7,10 +7,10 @@ #include "string/sprintf/snprintf.h" #include -#include +#include -extern inline int snprintf_(char *restrict s, size_t size, +extern inline int snprintf_(char *restrict s, ssize_t size, const char *restrict fmt, ...); -extern inline int vsnprintf_(char *restrict s, size_t size, +extern inline int vsnprintf_(char *restrict s, ssize_t size, const char *restrict fmt, va_list ap); diff --git a/lib/string/sprintf/snprintf.h b/lib/string/sprintf/snprintf.h index dc6009457..62be87492 100644 --- a/lib/string/sprintf/snprintf.h +++ b/lib/string/sprintf/snprintf.h @@ -10,8 +10,8 @@ #include #include -#include #include +#include #include "attr.h" #include "sizeof.h" @@ -25,15 +25,14 @@ format_attr(printf, 3, 4) -inline int snprintf_(char *restrict s, size_t size, const char *restrict fmt, - ...); +inline int snprintf_(char *restrict s, ssize_t size, const char *restrict fmt, ...); format_attr(printf, 3, 0) -inline int vsnprintf_(char *restrict s, size_t size, const char *restrict fmt, +inline int vsnprintf_(char *restrict s, ssize_t size, const char *restrict fmt, va_list ap); inline int -snprintf_(char *restrict s, size_t size, const char *restrict fmt, ...) +snprintf_(char *restrict s, ssize_t size, const char *restrict fmt, ...) { int len; va_list ap; @@ -47,14 +46,14 @@ snprintf_(char *restrict s, size_t size, const char *restrict fmt, ...) inline int -vsnprintf_(char *restrict s, size_t size, const char *restrict fmt, va_list ap) +vsnprintf_(char *restrict s, ssize_t size, const char *restrict fmt, va_list ap) { int len; len = vsnprintf(s, size, fmt, ap); if (len == -1) return -1; - if ((size_t) len >= size) { + if (len >= size) { errno = E2BIG; return -1; }