Skip to content

clang warnings - Format string type mismatches #329

Description

@voretaq7

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions