chiark / gitweb /
Replace the one use of sprintf() with snprintf()
authorBen Harris <bjh21@bjh21.me.uk>
Thu, 13 Mar 2025 13:49:43 +0000 (13:49 +0000)
committerBen Harris <bjh21@bjh21.me.uk>
Thu, 13 Mar 2025 13:49:43 +0000 (13:49 +0000)
It only acts on constant strings, so it can't actually overflow, but
this way I can assert() that it really doesn't.

bedstead.c

index a875585d7a0d66932497578c41fe93da86d76abe..d524564f6052c145a9c6d6d2546dc6b1d867d1d9 100644 (file)
@@ -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;
 }