From: Ben Harris Date: Thu, 13 Mar 2025 13:49:43 +0000 (+0000) Subject: Replace the one use of sprintf() with snprintf() X-Git-Tag: bedstead-3.252~3 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~bjharris/git?a=commitdiff_plain;h=bcd1d5304a76609feda859c6ed65076a525f9484;p=bedstead.git Replace the one use of sprintf() with snprintf() It only acts on constant strings, so it can't actually overflow, but this way I can assert() that it really doesn't. --- diff --git a/bedstead.c b/bedstead.c index a875585..d524564 100644 --- a/bedstead.c +++ b/bedstead.c @@ -3108,8 +3108,11 @@ get_fullname(void) { #define FULLNAME_MAX 100 static char fullname[FULLNAME_MAX]; + int len; - sprintf(fullname, FAMILY_NAME "%s%s", weight->suffix, width->suffix); + len = snprintf(fullname, sizeof(fullname), + FAMILY_NAME "%s%s", weight->suffix, width->suffix); + assert(len >= 0 && (unsigned)len < sizeof(fullname)); return fullname; }