Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -Werror=format-security back #357

Merged
merged 2 commits into from
Jul 4, 2021

Conversation

withinwheels
Copy link
Contributor

Turn off very common formatting issues and fix the remainder

@withinwheels
Copy link
Contributor Author

Hm. This one fails the linux CI build with

cc: error: unrecognized command line option ‘-Wformat-overflow=0’
cc: error: unrecognized command line option ‘-Wformat-truncation=0’

(So, this is not ready to merge.)

@ghost
Copy link

ghost commented Jun 21, 2021

The seeds are now 64 bits (uint64_t). To print them correctly, we need to use %lu on 64-bit platforms... but %llu on 32-bit platforms. Fortunately, C99 introduced a portable way to support both:

#include <inttypes.h>

    printf("Seed %" PRIu64 ":\n", theSeed);

Alternatively, an explicit cast also works on all platforms, and is already used in 3 other places:

    printf("Seed %llu:\n", (unsigned long long)theSeed);

Ah, format-overflow was introduced in GCC 7.2. The build system must be using an older version. Not sure what the best solution is: checking compiler version? a separate make target for format warnings?

@withinwheels
Copy link
Contributor Author

Fortunately, C99 introduced a portable way to support both

Thank you, I'll incorporate that.

Not sure what the best solution is

The original motivation was to compile when CFLAGS includes -Werror=format-security, to satisfy arch linux (I believe it is that option which it sets by default?) One would hope that a work-around would be compatible with that.

@tmewett
Copy link
Owner

tmewett commented Jun 21, 2021

Is using %llu for 64bit not correct/portable? long long is >=64

The Ubuntu 16.04 Actions environment gets deprecated in September, we could upgrade now

@ghost
Copy link

ghost commented Jun 21, 2021

Is using %llu for 64bit not correct/portable? long long is >=64

Probably fine (it works on gcc and clang in practice, after all!) but if some other compiler wants to treat long long as 128 bits, I'm not sure that printf wouldn't screw something up when given %llu (128 bits) in the format string, but uint64_t (64 bits) in the parameters. I think that's why -Werror=format-security gives a warning.

Turn off very common formatting issues and fix the remainder
@withinwheels withinwheels force-pushed the ww/add-format-security-back branch from 1fdb96d to 9beb18a Compare June 22, 2021 03:45
@withinwheels
Copy link
Contributor Author

Ok. Explicit casts and ubuntu 18.04 are in. My own local CI passes. I think we're mergeable, thoughts?

@tmewett
Copy link
Owner

tmewett commented Jul 3, 2021

What do we think of using PRIu64?

@withinwheels
Copy link
Contributor Author

withinwheels commented Jul 3, 2021

What do we think of using PRIu64?

My guess is it would seem less intuitive to a future maintainer than the explicit casts. I doubt we care about any precision/sizing/overflow implications of the explicit cast either.

@tmewett
Copy link
Owner

tmewett commented Jul 4, 2021

Hmm, I might prefer it from a type abstraction POV. At one point I was considering a seed_t type, maybe with equiv PRIseed macro - but because C, it's a useless abstraction for anything but clarity/intent, as to program correctly in all cases one must know its size and signedness. So ok, let's go with this. TY!

@tmewett tmewett changed the base branch from master to release July 4, 2021 17:13
@tmewett tmewett merged commit decee98 into tmewett:release Jul 4, 2021
@withinwheels withinwheels deleted the ww/add-format-security-back branch July 4, 2021 19:08
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.

2 participants