Skip to content

fixes silent integer truncation for narrow types in Converter#207

Open
MarkLee131 wants to merge 1 commit intod99kris:masterfrom
MarkLee131:fix/narrow-integer-truncation
Open

fixes silent integer truncation for narrow types in Converter#207
MarkLee131 wants to merge 1 commit intod99kris:masterfrom
MarkLee131:fix/narrow-integer-truncation

Conversation

@MarkLee131
Copy link
Copy Markdown

Fix #206:

When converting CSV cell values to signed char, unsigned char, short, or unsigned short, std::stoi returns an int which is then silently truncated via static_cast. For example, "256" read as unsigned char silently becomes 0, and "32768" read as short becomes -32768.

Add range checks against std::numeric_limits before the static_cast, throwing std::out_of_range when the value does not fit. Add test104 to verify range checking for all four narrow integer types.

When converting CSV cell values to signed char, unsigned char, short,
or unsigned short, std::stoi returns an int which is then silently
truncated via static_cast. For example, "256" read as unsigned char
silently becomes 0, and "32768" read as short becomes -32768.

Add range checks against std::numeric_limits before the static_cast,
throwing std::out_of_range when the value does not fit. Add test104 to
verify range checking for all four narrow integer types.
@d99kris d99kris self-assigned this Mar 29, 2026
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.

Silent integer truncation for narrow types (signed char, unsigned char, short, unsigned short)

2 participants