From 346d6059149c1073655484d88f9311b2cb4c58c7 Mon Sep 17 00:00:00 2001 From: Dewey Dunnington Date: Fri, 23 Oct 2026 21:22:14 -0500 Subject: [PATCH] fix(ci): address Ubuntu 26 compiler diagnostics --- src/nanoarrow/common/utils_test.cc | 21 ++++++++--------- src/nanoarrow/hpp/view_test.cc | 12 ++++++---- src/nanoarrow/integration/ipc_integration.cc | 24 +++++++++++++++----- 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/nanoarrow/common/utils_test.cc b/src/nanoarrow/common/utils_test.cc index 0d52d0f95..5303f1f5b 100644 --- a/src/nanoarrow/common/utils_test.cc +++ b/src/nanoarrow/common/utils_test.cc @@ -267,11 +267,14 @@ TEST(DecimalTest, Decimal32Test) { #if defined(NANOARROW_BUILD_TESTS_WITH_ARROW) && ARROW_VERSION_MAJOR >= 18 auto dec_pos = *Decimal32::FromString("12.345"); - uint8_t bytes_pos[4]; + // ArrowDecimalSetBytes() accepts buffers for all decimal widths. Allocate enough + // space for either branch so bounds-checking compilers do not diagnose the + // unreachable Decimal64 copy below. + uint8_t bytes_pos[sizeof(uint64_t)] = {}; dec_pos.ToBytes(bytes_pos); auto dec_neg = *Decimal32::FromString("-34.567"); - uint8_t bytes_neg[4]; + uint8_t bytes_neg[sizeof(uint64_t)] = {}; dec_neg.ToBytes(bytes_neg); #endif @@ -279,24 +282,18 @@ TEST(DecimalTest, Decimal32Test) { EXPECT_EQ(ArrowDecimalGetIntUnsafe(&decimal), 12345); EXPECT_EQ(ArrowDecimalSign(&decimal), 1); #if defined(NANOARROW_BUILD_TESTS_WITH_ARROW) && ARROW_VERSION_MAJOR >= 18 - EXPECT_EQ(memcmp(decimal.words, bytes_pos, sizeof(bytes_pos)), 0); - ASSERT_EQ(decimal.n_words, 0); - // This duplicative assert suppresses array-bounds warnings with release builds - assert(decimal.n_words == 0); + EXPECT_EQ(memcmp(decimal.words, bytes_pos, sizeof(int32_t)), 0); ArrowDecimalSetBytes(&decimal, bytes_pos); - EXPECT_EQ(memcmp(decimal.words, bytes_pos, sizeof(bytes_pos)), 0); + EXPECT_EQ(memcmp(decimal.words, bytes_pos, sizeof(int32_t)), 0); #endif ArrowDecimalSetInt(&decimal, -34567); EXPECT_EQ(ArrowDecimalGetIntUnsafe(&decimal), -34567); EXPECT_EQ(ArrowDecimalSign(&decimal), -1); #if defined(NANOARROW_BUILD_TESTS_WITH_ARROW) && ARROW_VERSION_MAJOR >= 18 - EXPECT_EQ(memcmp(decimal.words, bytes_neg, sizeof(bytes_neg)), 0); - ASSERT_EQ(decimal.n_words, 0); - // This duplicative assert suppresses array-bounds warnings with release builds - assert(decimal.n_words == 0); + EXPECT_EQ(memcmp(decimal.words, bytes_neg, sizeof(int32_t)), 0); ArrowDecimalSetBytes(&decimal, bytes_neg); - EXPECT_EQ(memcmp(decimal.words, bytes_neg, sizeof(bytes_neg)), 0); + EXPECT_EQ(memcmp(decimal.words, bytes_neg, sizeof(int32_t)), 0); #endif } diff --git a/src/nanoarrow/hpp/view_test.cc b/src/nanoarrow/hpp/view_test.cc index d420269ec..b94233133 100644 --- a/src/nanoarrow/hpp/view_test.cc +++ b/src/nanoarrow/hpp/view_test.cc @@ -15,6 +15,8 @@ // specific language governing permissions and limitations // under the License. +#include + #include #include @@ -107,9 +109,9 @@ TEST_P(BinaryViewTypeTestFixture, NanoarrowHppViewBinaryViewArrayAsBytesTest) { array->offset = offset; array->length = array->length - offset; - ArrowStringView expected[] = {"foo"_asv, ""_asv, - "this_string_is_longer_than_inline"_asv, ""_asv, - "here_is_another_string"_asv}; + std::array expected = {"foo"_asv, ""_asv, + "this_string_is_longer_than_inline"_asv, + ""_asv, "here_is_another_string"_asv}; nanoarrow::UniqueArrayView array_view{}; ArrowArrayViewInitFromType(array_view.get(), type); @@ -120,7 +122,7 @@ TEST_P(BinaryViewTypeTestFixture, NanoarrowHppViewBinaryViewArrayAsBytesTest) { if (i == 1 || i == 3) { EXPECT_EQ(slot, nanoarrow::NA); } else { - EXPECT_EQ(slot, expected[i]); + EXPECT_EQ(slot, expected.at(i)); } ++i; } @@ -130,7 +132,7 @@ TEST_P(BinaryViewTypeTestFixture, NanoarrowHppViewBinaryViewArrayAsBytesTest) { if (i == 1 || i == 3) { EXPECT_EQ(slot, nanoarrow::NA); } else { - EXPECT_EQ(slot, expected[i]); + EXPECT_EQ(slot, expected.at(i)); } ++i; } diff --git a/src/nanoarrow/integration/ipc_integration.cc b/src/nanoarrow/integration/ipc_integration.cc index 7a56fca70..feea4d82a 100644 --- a/src/nanoarrow/integration/ipc_integration.cc +++ b/src/nanoarrow/integration/ipc_integration.cc @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -115,14 +116,25 @@ struct File { } std::string read() const { - fseek(file_, 0, SEEK_END); - std::string contents(ftell(file_), '\0'); - rewind(file_); + if (fseek(file_, 0, SEEK_END) != 0) { + throw std::runtime_error("Could not seek to the end of the input file"); + } + + long file_size = ftell(file_); + if (file_size < 0) { + throw std::runtime_error("Could not determine the input file size"); + } - size_t bytes_read = 0; - while (bytes_read < contents.size()) { - bytes_read += fread(&contents[bytes_read], 1, contents.size() - bytes_read, file_); + if (fseek(file_, 0, SEEK_SET) != 0) { + throw std::runtime_error("Could not seek to the beginning of the input file"); } + + std::string contents(static_cast(file_size), '\0'); + if (!contents.empty() && + fread(&contents[0], 1, contents.size(), file_) != contents.size()) { + throw std::runtime_error("Could not read the complete input file"); + } + return contents; }