#14730 closed bug (fixed)
towlower() and towupper() should check the character range when gLocaleBackend is NULL.
Reported by: | korli | Owned by: | nobody |
---|---|---|---|
Priority: | normal | Milestone: | R1/beta2 |
Component: | System/POSIX | Version: | R1/Development |
Keywords: | Cc: | ||
Blocked By: | Blocking: | ||
Platform: | All |
Description
tolower and toupper are only valid for unsigned char types. see https://github.com/haikuports/haikuports/issues/3410 for reference.
Something like this:
wint_t towlower(wint_t wc) { if (gLocaleBackend == NULL) { if (wc < 0 || wc > 127) return 0; return tolower(wc); } wint_t result = wc; gLocaleBackend->ToWCTrans(wc, _ISlower, result); return result; } wint_t towupper(wint_t wc) { if (gLocaleBackend == NULL) { if (wc < 0 || wc > 127) return 0; return toupper(wc); } wint_t result = wc; gLocaleBackend->ToWCTrans(wc, _ISupper, result); return result; }
Change History (4)
comment:1 by , 6 years ago
comment:4 by , 5 years ago
Milestone: | Unscheduled → R1/beta2 |
---|
Assign tickets with status=closed and resolution=fixed within the R1/beta2 development window to the R1/beta2 Milestone
Note:
See TracTickets
for help on using tickets.
It should return wc rather than returning 0, for out of range characters.
http://pubs.opengroup.org/onlinepubs/9699919799/functions/towlower.html
Current implementation: https://git.haiku-os.org/haiku/tree/src/system/libroot/posix/locale/wctype.cpp#n124
It would be nice if tolower/toupper did not crash for out of range characters, however. Maybe we should put the range check there instead? However I see tolower/toupper are gcc builtins, so it's possible it knows the expected input ranges and will optimize away attempts to check it (already happened to us in other cases, leading to disabling the tree-vrp optimization back then).