Skip to content

boot_serial: Fix incorrect format specifier for off_t #1413

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

Merged
merged 1 commit into from
Aug 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion boot/boot_serial/src/boot_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ static off_t erase_range(const struct flash_area *fap, off_t start, off_t end)
}

size = flash_sector_get_off(&sect) + flash_sector_get_size(&sect) - start;
BOOT_LOG_INF("Erasing range 0x%x:0x%x", start, start + size - 1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not to cast this to ssize and use z?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because ssize_t is not guaranteed to be the largest integer type supported and/or the same size as off_t.

Copy link
Collaborator

@de-nordic de-nordic Jul 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because ssize_t is not guaranteed to be the largest integer type supported and/or the same size as off_t.

We should probably replace the off_t, here, with the uint32_t, including the erase_range definition; I do not think that we need offsets and sizes greater than 32-bit here (for example Zephyr flash_map sizes are uint32_t). Than just use llx and cast expressions to unsigned long long - this should cover both 32 and 64 bit systems for us.
Scratch that, is should be possible to access slot anywhere on the external flash, so it means that it may be beyond 32-bit range, so off_t would be correct here, if we can make off_t 64bit on 32bit machines to make this work.

BOOT_LOG_INF("Erasing range 0x%jx:0x%jx", (intmax_t)start,
(intmax_t)(start + size - 1));

rc = flash_area_erase(fap, start, size);
if (rc != 0) {
Expand Down