zhjwpku commented on code in PR #748:
URL: https://github.com/apache/iceberg-cpp/pull/748#discussion_r3417704100


##########
src/iceberg/util/string_util.h:
##########
@@ -128,6 +132,18 @@ class ICEBERG_EXPORT StringUtils {
     }
     return value;
   }
+
+ private:
+  // std::tolower/std::toupper require their argument to be representable as
+  // unsigned char (or EOF); passing a raw char with a non-ASCII (negative) 
value is
+  // undefined behavior, so cast through unsigned char first.

Review Comment:
   +1, Quoting cppreference:
   
   Like all other functions from 
[\<cctype\>](https://en.cppreference.com/cpp/header/cctype), the behavior of 
std::tolower is undefined if the argument's value is neither representable as 
unsigned char nor equal to EOF. To use these functions safely with plain chars 
(or signed chars), the argument should first be converted to unsigned char:
   
   ```
   char my_tolower(char ch)
   {
       return static_cast<char>(std::tolower(static_cast<unsigned char>(ch)));
   }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to