Skip to content

tests: Fix format specifier for size_t variable in test_read_file - #26

Merged
Harshal Dev (harshaldev27) merged 1 commit into
qualcomm:mainfrom
nparamat:github_ci
Jul 2, 2026
Merged

Harshal Dev (harshaldev27) merged 1 commit into
qualcomm:mainfrom
nparamat:github_ci

Conversation

@nparamat

Copy link
Copy Markdown
Contributor

The format specifier %u expects an unsigned int argument, but file_size is declared as size_t. On 64-bit architectures, size_t is 64 bits wide while unsigned int is 32 bits, so using %u can silently truncate large file sizes when printing diagnostic messages.

This mismatch also triggers -Wformat compiler warnings, which become hard build failures when -Werror is enabled. The issue affects two diagnostic messages in test_read_file: one reporting an undersized user-provided buffer, and one logging the number of bytes being read from a file.

Replace %u with %zu, the correct and portable format specifier for size_t as mandated by the C99 standard. This fixes the truncation risk and resolves the -Wformat warning on both 32-bit and 64-bit target architectures with no change in functional behavior.

The format specifier %u expects an unsigned int argument, but
file_size is declared as size_t. On 64-bit architectures, size_t
is 64 bits wide while unsigned int is 32 bits, so using %u can
silently truncate large file sizes when printing diagnostic
messages.

This mismatch also triggers -Wformat compiler warnings, which
become hard build failures when -Werror is enabled. The issue
affects two diagnostic messages in test_read_file: one reporting
an undersized user-provided buffer, and one logging the number of
bytes being read from a file.

Replace %u with %zu, the correct and portable format specifier for
size_t as mandated by the C99 standard. This fixes the truncation
risk and resolves the -Wformat warning on both 32-bit and 64-bit
target architectures with no change in functional behavior.

Signed-off-by: Naresh Paramata <nparamat@qti.qualcomm.com>
@harshaldev27
Harshal Dev (harshaldev27) merged commit 34fa819 into qualcomm:main Jul 2, 2026
2 checks passed
@nparamat
nparamat deleted the github_ci branch July 24, 2026 09:13
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