tests: Fix format specifier for size_t variable in test_read_file - #26
Merged
Merged
Conversation
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>
Harshal Dev (harshaldev27)
approved these changes
Jul 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.