Skip to content

Fix some compiler warnings#4

Open
magical wants to merge 3 commits intoBR903:masterfrom
magical:warnings
Open

Fix some compiler warnings#4
magical wants to merge 3 commits intoBR903:masterfrom
magical:warnings

Conversation

@magical
Copy link
Copy Markdown
Contributor

@magical magical commented Apr 16, 2020

Details on the commits.

I found the format string problems by annotating warn, errmsg, and die with GCC's format attribute. https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-format-function-attribute

extern void _warn(char const *fmt, ...)  __attribute__((format (printf, 1, 2)));
extern void _errmsg(char const *prefix, char const *fmt, ...)  __attribute__((format (printf, 2, 3)));;
extern void _die(char const *fmt, ...)  __attribute__((format (printf, 1, 2)));;

I'm not sure how you feel about adding GCC-specific attributes to the code so i left that change out of the PR.

magical added 3 commits April 16, 2020 16:20
This suppresses a warning from gcc -Wimplicit-fallthrough, which is
enabled by -Wextra.

The braces around the body of the if statement are necessary here,
as otherwise gcc doesn't notice the fallthrough comment. I'm guessing
that without them it attributes the comment to the statement inside the
if.
Fixes the following warning:

    series.c:196:43: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘long int’ [-Wformat=]

The argument in question is a ptrdiff_t, so the correct format specifier
is `%td`.
Fixes the following warnings:

    sdlout.c:269:40: warning: format ‘%d’ expects a matching ‘int’ argument [-Wformat=]
    sdlout.c:269:43: warning: format ‘%d’ expects a matching ‘int’ argument [-Wformat=]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant