Skip to content

Commit 6dc6623

Browse files
apacheGH-41433: [C++][Gandiva] Fix ascii_utf8 function to return same result on x86 and Arm (apache#41434)
### Rationale for this change Fixing ascii_utf8 function that has different return result on x86 and Arm due to default char type sign difference on those platforms. Added tests to cover existing x86 behavior for ascii symbols with code >127. ### What changes are included in this PR? 1. Added type cast to signed char to save existing x86 behavior on Arm platform. 2. Added tests cases for negative results. ### Are these changes tested? UT included. ### Are there any user-facing changes? None * GitHub Issue: apache#41433 Authored-by: DenisTarasyuk <[email protected]> Signed-off-by: Sutou Kouhei <[email protected]>
1 parent d60ff53 commit 6dc6623

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

cpp/src/gandiva/precompiled/string_ops.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1377,7 +1377,7 @@ gdv_int32 ascii_utf8(const char* data, gdv_int32 data_len) {
13771377
if (data_len == 0) {
13781378
return 0;
13791379
}
1380-
return static_cast<gdv_int32>(data[0]);
1380+
return static_cast<gdv_int32>(static_cast<signed char>(data[0]));
13811381
}
13821382

13831383
// Returns the ASCII character having the binary equivalent to A.

cpp/src/gandiva/precompiled/string_ops_test.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ TEST(TestStringOps, TestAscii) {
5151
EXPECT_EQ(ascii_utf8("", 0), 0);
5252
EXPECT_EQ(ascii_utf8("123", 3), 49);
5353
EXPECT_EQ(ascii_utf8("999", 3), 57);
54+
EXPECT_EQ(ascii_utf8("\x80", 1), -128);
55+
EXPECT_EQ(ascii_utf8("\xFF", 1), -1);
5456
}
5557

5658
TEST(TestStringOps, TestChrBigInt) {

0 commit comments

Comments
 (0)