From 52038a21fc8c874a765f34f19237fdcfee10ad4a Mon Sep 17 00:00:00 2001 From: metsw24-max Date: Mon, 8 Jun 2026 14:15:41 +0530 Subject: [PATCH] cast to unsigned char before ctype calls in gandiva precompiled --- cpp/src/gandiva/precompiled/string_ops.cc | 16 +++++++++------- cpp/src/gandiva/precompiled/time.cc | 6 +++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/cpp/src/gandiva/precompiled/string_ops.cc b/cpp/src/gandiva/precompiled/string_ops.cc index 035d3c8c62e1..b6d6fed236e1 100644 --- a/cpp/src/gandiva/precompiled/string_ops.cc +++ b/cpp/src/gandiva/precompiled/string_ops.cc @@ -2300,7 +2300,8 @@ const char* binary_string(gdv_int64 context, const char* text, gdv_int32 text_le (text[i + 1] == 'x' || text[i + 1] == 'X')) { char hd1 = text[i + 2]; char hd2 = text[i + 3]; - if (isxdigit(hd1) && isxdigit(hd2)) { + if (isxdigit(static_cast(hd1)) && + isxdigit(static_cast(hd2))) { // [a-fA-F0-9] ret[j] = to_binary_from_hex(hd1) * 16 + to_binary_from_hex(hd2); i += 3; @@ -2345,7 +2346,7 @@ const char* binary_string(gdv_int64 context, const char* text, gdv_int32 text_le int read_index = 0; \ while (read_index < in_len) { \ char c1 = in[read_index]; \ - if (isxdigit(c1)) { \ + if (isxdigit(static_cast(c1))) { \ digit = to_binary_from_hex(c1); \ \ OUT_TYPE next = result * 16 - digit; \ @@ -2916,7 +2917,8 @@ const char* from_hex_utf8(int64_t context, const char* text, int32_t text_len, for (int32_t i = 0; i < text_len; i += 2) { char b1 = text[i]; char b2 = text[i + 1]; - if (isxdigit(b1) && isxdigit(b2)) { + if (isxdigit(static_cast(b1)) && + isxdigit(static_cast(b2))) { // [a-fA-F0-9] ret[j++] = to_binary_from_hex(b1) * 16 + to_binary_from_hex(b2); } else { @@ -2984,9 +2986,9 @@ const char* soundex_utf8(gdv_int64 context, const char* in, gdv_int32 in_len, int start_idx = 0; for (int i = 0; i < in_len; ++i) { - if (isalpha(in[i]) > 0) { + if (isalpha(static_cast(in[i])) > 0) { // Retain the first letter - ret[0] = toupper(in[i]); + ret[0] = toupper(static_cast(in[i])); start_idx = i + 1; break; } @@ -3002,8 +3004,8 @@ const char* soundex_utf8(gdv_int64 context, const char* in, gdv_int32 in_len, soundex[0] = '\0'; // Replace consonants with digits and special letters with 0 for (int i = start_idx; i < in_len; i++) { - if (isalpha(in[i]) > 0) { - c = toupper(in[i]) - 65; + if (isalpha(static_cast(in[i])) > 0) { + c = toupper(static_cast(in[i])) - 65; if (mappings[c] != soundex[si - 1]) { soundex[si] = mappings[c]; si++; diff --git a/cpp/src/gandiva/precompiled/time.cc b/cpp/src/gandiva/precompiled/time.cc index 8414d0ed37cf..d85e448f42aa 100644 --- a/cpp/src/gandiva/precompiled/time.cc +++ b/cpp/src/gandiva/precompiled/time.cc @@ -643,7 +643,7 @@ gdv_date64 castDATE_utf8(int64_t context, const char* input, gdv_int32 length) { int dateIndex = 0, index = 0, value = 0; int year_str_len = 0; while (dateIndex < 3 && index < length) { - if (!isdigit(input[index])) { + if (!isdigit(static_cast(input[index]))) { dateFields[dateIndex++] = value; value = 0; } else { @@ -713,7 +713,7 @@ gdv_timestamp castTIMESTAMP_utf8(int64_t context, const char* input, gdv_int32 l int year_str_len = 0, sub_seconds_len = 0; int ts_field_index = TimeFields::kYear, index = 0, value = 0; while (ts_field_index < TimeFields::kMax && index < length) { - if (isdigit(input[index])) { + if (isdigit(static_cast(input[index]))) { value = (value * 10) + (input[index] - '0'); if (ts_field_index == TimeFields::kYear) { year_str_len++; @@ -842,7 +842,7 @@ gdv_time32 castTIME_utf8(int64_t context, const char* input, int32_t length) { bool has_invalid_digit = false; while (time_field_idx < TimeFields::kDisplacementHours && index < length) { - if (isdigit(input[index])) { + if (isdigit(static_cast(input[index]))) { value = (value * 10) + (input[index] - '0'); if (time_field_idx == TimeFields::kSubSeconds) {