Skip to content

Silent narrowing conversion(s) from size_t to printf_size_t may bite us #87

@eyalroz

Description

@eyalroz

printf()-family functions have the questionable design choice of returning int as the number of characters printed, despite buffer lengths possibly being larger than INT_MAX.

In our implementation, this is compounded by us using an int-sized printf_size_t type for offsets and lengths within the buffer, corresponding to the final return type - while taking in a size_t for functions such as snprintf(). At the moment, we simply cast from the latter into the former type at various locations, never checking for overflow. This could theoretically result in us getting lengths of 0, or other short lengths, which will mess up our behavior.

We need to cast as early as possible, and discard the size_t inputs.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingresolved-on-developA changeset fixing this issue has been commiutted to the development branch

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions