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

clang warnings - Format string type mismatches #329

Open
voretaq7 opened this issue May 10, 2019 · 0 comments
Open

clang warnings - Format string type mismatches #329

voretaq7 opened this issue May 10, 2019 · 0 comments

Comments

@voretaq7
Copy link
Contributor

clang sent me down a rabbit hole about format string mismatches of the form:

warning: format '%lld' expects argument of type 'long long int', 
         but argument 9 has type 'off_t' {aka 'long int'}

This stems from the logic in largefile.h that makes some assumptions about integer type widths which don't hold up on all platforms (specifically ones where int is a 64-bit integer), and clang being appropriately pedantic about numeric format strings matching their parameters' type, not just bit-width.

Similar assumptions are made in selecting strtol() vs. strtoll() so it looks like this logic would break completely on esoteric platforms (anything with 128-bit long long time_t or off_t would come back as regular longs, which might only be 64-bit).

A possible quick-and-dirty fix for the format string warnings: "If strtoll exists use it, cast off_t and time_t to long long in the printf calls, and use %lld as the format string. If not use strtol, cast to long, and use %ld as the format string."
(Really there's no reason strtoll shouldn't exist - it's 1990 ANSI C - so this would effectively always land us in the first case.)

I don't think the above would break anything so I might propose a PR to do exactly that, but maybe someone has a more elegant idea?

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

No branches or pull requests

1 participant