quake: fix crash from strange printf behavior (FS#13821)

This was a latent bug exposed by commit a3f2b64a46
("Enable float formatting in printf"). The version
number is passed as 1.09f, but somehow ends up printing
a string that is so huge it overruns the destination
buffer and corrupts the return address on the stack.

Using snprintf prevents the buffer overrun and gets
quake working again, though this doesn't address the
underlying bug with printf.

Change-Id: I37e4426bc6ebca42d83b5a3b659da497b652d1ae
This commit is contained in:
Aidan MacDonald 2026-04-22 19:23:59 +01:00
parent e661c35b29
commit f9a5d6fe86

View file

@ -548,7 +548,7 @@ void Draw_ConsoleBackground (int lines)
conback = Draw_CachePic ("gfx/conback.lmp");
dest = conback->data + 320 - 43 + 320*186;
sprintf (ver, "%.2f", (float)VERSION);
snprintf (ver, sizeof(ver), "%.2f", (float)VERSION);
for (x=0 ; x<strlen(ver) ; x++)
Draw_CharToConback (ver[x], dest+(x<<3));