]> git.ipfire.org Git - thirdparty/gcc.git/commit
libgcobol: Fix uses of tolower and toupper with std::transform
authorJonathan Wakely <jwakely@redhat.com>
Tue, 18 Mar 2025 21:17:03 +0000 (21:17 +0000)
committerJames K. Lowden <jklowden@cobolworx.com>
Wed, 26 Mar 2025 20:49:11 +0000 (16:49 -0400)
commite2c93a07d739034e5375e69da38091efc87d56e9
tree91786d87191cf7c74ffdde15644aed5df665a99d
parentb1a58dcb238c5a48e24f226c89287595ef7a9225
libgcobol: Fix uses of tolower and toupper with std::transform

As explained in the libstdc++ manual[1] and elsewhere[2], using tolower
and toupper in std::transform directly is wrong. If char is signed then
non-ASCII characters with negative values lead to undefined behaviour.
Also, tolower and toupper are overloaded names in C++ so expecting them
to resolve to a unique function pointer is unreliable. Finally, the
<cctype> header was included, not <ctype.h>, so they should have been
qualified as std::tolower and std::toupper.

[1] https://gcc.gnu.org/onlinedocs/libstdc++/manual/strings.html#strings.string.simple
[2] https://en.cppreference.com/w/cpp/string/byte/tolower

libgcobol/ChangeLog:

* intrinsic.cc (is_zulu_format): Qualify toupper and cast
argument to unsigned char.
(fill_cobol_tm): Likewise.
(iscasematch): Likewise for to lower.
(numval): Qualify calls to tolower.
(__gg__lower_case): Use lambda expression for
tolower call.
(__gg__upper_case): Likewise for toupper call.
* libgcobol.cc (mangler_core): Cast tolower argument to unsigned
char.
* valconv.cc (__gg__string_to_numeric_edited): Cast to upper
arguments to unsigned char.
libgcobol/intrinsic.cc
libgcobol/libgcobol.cc
libgcobol/valconv.cc