Summary
Three fprintf calls in dsub.c use %d to format long int values, producing undefined behavior on 64-bit platforms.
Background
The CI pipeline introduced in PR #38 revealed three -Wformat warnings from both GCC and Clang when compiling dsub.c.
The function rspsb2nl_ declares x as long (line 67) and iloc is assigned from ftell() which returns long (line 111), but the error-reporting fprintf calls on lines 84, 96, and 114 all use %d (which expects int).
On 64-bit platforms where long is 8 bytes and int is 4 bytes, this is undefined behavior per the C standard and could print garbled values in database error messages.
Details
dsub.c:84 — fprintf(stderr, "Error seeking database loc %d\n", x); — x is long
dsub.c:96 — fprintf(stderr, "Error reading database loc %d\n", x); — x is long
dsub.c:114 — fprintf(stderr, "Error seeking database loc %d\n", iloc); — iloc is long (from ftell())
Fix: change %d to %ld in all three calls.
This does not alter game logic — it only corrects the format specifiers in error-handling code paths.
This can be fixed as part of v1.1.0, but will most likely be addressed in a future release to help get recent changes submitted downstream in the Fedora package.
Outcome
The codebase compiles without -Wformat warnings and database error messages display correct seek/read positions on all platforms.
Summary
Three
fprintfcalls indsub.cuse%dto formatlong intvalues, producing undefined behavior on 64-bit platforms.Background
The CI pipeline introduced in PR #38 revealed three
-Wformatwarnings from both GCC and Clang when compilingdsub.c.The function
rspsb2nl_declaresxaslong(line 67) andilocis assigned fromftell()which returnslong(line 111), but the error-reportingfprintfcalls on lines 84, 96, and 114 all use%d(which expectsint).On 64-bit platforms where
longis 8 bytes andintis 4 bytes, this is undefined behavior per the C standard and could print garbled values in database error messages.Details
dsub.c:84—fprintf(stderr, "Error seeking database loc %d\n", x);—xislongdsub.c:96—fprintf(stderr, "Error reading database loc %d\n", x);—xislongdsub.c:114—fprintf(stderr, "Error seeking database loc %d\n", iloc);—ilocislong(fromftell())Fix: change
%dto%ldin all three calls.This does not alter game logic — it only corrects the format specifiers in error-handling code paths.
This can be fixed as part of v1.1.0, but will most likely be addressed in a future release to help get recent changes submitted downstream in the Fedora package.
Outcome
The codebase compiles without
-Wformatwarnings and database error messages display correct seek/read positions on all platforms.