Skip to content

Format string mismatch in osdp_diag.c: %d used for size_t argument #283

@undici77

Description

@undici77

Bug description
A format string mismatch in src/osdp_diag.c causes a compiler warning: the %d format specifier is used for an argument of type size_t, which leads to undefined behavior on 64-bit platforms where int and size_t differ in size (e.g., macOS, Linux x86_64).

Expected behavior
The build should complete without warnings when compiled with strict warning flags (e.g., -Wformat). The log message should correctly print the packet count using the appropriate format specifier for size_t.

Observed behavior
The compiler emits a warning:

warning: format specifies type 'int' but the argument has type 'size_t' (aka 'unsigned long') [-Wformat]
LOG_INF("Captured %d packets", num_packets);
~~           ^~~~~~~~~~~
%zu

at line 55 in src/osdp_diag.c.

Additional context

  • Compiler: Apple Clang 15.0+ (and other modern compilers with -Wformat)
  • Platform: macOS (64-bit), but also affects Linux/Unix 64-bit builds
  • Build system: CMake with debug configuration (cmake --build ...)
  • The variable num_packets is declared as size_t, but the format string incorrectly uses %d.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions