Skip to content

Ztring: TrimRight without a size_t wrap-around - #238

Merged
JeromeMartinez merged 1 commit into
MediaArea:masterfrom
JeromeMartinez:Ztring_TrimRight_NoWrap
Nov 30, 2026
Merged

JeromeMartinez merged 1 commit into
MediaArea:masterfrom
JeromeMartinez:Ztring_TrimRight_NoWrap

Conversation

@JeromeMartinez

@JeromeMartinez JeromeMartinez commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Since #236 (/std:c++latest), MSVC with /sdl applies guard(overflow) to the count of basic_string::assign(const Char*, size_type). TrimRight relied on Last+1 wrapping from SIZE_MAX to 0 when the whole string is made of the trimmed character: this count is now saturated to SIZE_MAX and std::length_error ("string too long") is thrown.

TrimRight now counts the trailing characters down and calls resize, without wrap-around. The result is unchanged.

With /std:c++latest and /sdl, MSVC applies guard(overflow) to the count
of basic_string::assign(const Char*, size_type): Last+1 wrapping from
SIZE_MAX to 0 for a string with only the trimmed character became
SIZE_MAX and std::length_error ("string too long") was thrown, e.g. for
an ID3v1 comment of spaces.
@JeromeMartinez
JeromeMartinez merged commit 9731f9d into MediaArea:master Nov 30, 2026
18 checks passed
@JeromeMartinez
JeromeMartinez deleted the Ztring_TrimRight_NoWrap branch November 30, 2026 08:35
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.

1 participant