The condition ‘c > 0x1F’ is clearly meant to test whether a character is
a control code or not. While it works for ASCII characters, when ‘char’
is signed it fails for codepoints above 0x7f, which get represented as
negative values. Make this calculation work as it was (presumably)
intended by casting to ‘unsigned char’.
Signed-off-by: Jo Sutton <josutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* Calculate the encoded length of a character for log_escape
*
*/
-static size_t encoded_length(char c)
+static size_t encoded_length(unsigned char c)
{
if (c != '\\' && c > 0x1F) {
return 1;
c = in;
e = encoded;
while (*c) {
- if (*c != '\\' && *c > 0x1F) {
+ if (*c != '\\' && (unsigned char)(*c) > 0x1F) {
*e++ = *c++;
} else {
switch (*c) {