This is an automated email from the ASF dual-hosted git repository.
paleolimbot pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-nanoarrow.git
The following commit(s) were added to refs/heads/main by this push:
new c61585a3 fix(ci): address Ubuntu 26 compiler diagnostics (#995)
c61585a3 is described below
commit c61585a30f7ac93cebf9a437f40e1715567bb246
Author: Dewey Dunnington <[email protected]>
AuthorDate: Sun Oct 25 22:13:44 2026 -0500
fix(ci): address Ubuntu 26 compiler diagnostics (#995)
Ubuntu 26.04 moved ubuntu-latest to GCC 15 and clang-tidy 21, exposing
one Werror array-bounds diagnostic and three analyzer warnings. Size
Decimal32 test buffers to cover inlined branches, use bounds-checked
access in view tests, and make integration file reads check seek, size,
and read failures.
Verified locally with GCC 15.2: CMake IPC/test build, 409 tests, and
clang-tidy 21 for the affected targets.
---
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 0d52d0f9..5303f1f5 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 d420269e..b9423313 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 <array>
+
#include <gmock/gmock-matchers.h>
#include <gtest/gtest.h>
@@ -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<ArrowStringView, 5> 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 7a56fca7..feea4d82 100644
--- a/src/nanoarrow/integration/ipc_integration.cc
+++ b/src/nanoarrow/integration/ipc_integration.cc
@@ -17,6 +17,7 @@
#include <cstdlib>
#include <sstream>
+#include <stdexcept>
#include <nanoarrow/nanoarrow_ipc.hpp>
#include <nanoarrow/nanoarrow_testing.hpp>
@@ -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<size_t>(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;
}