Skip to content

Commit 6b9c227

Browse files
committed
integer: suppress false-positive GCC 14.3.1 stringop-overflow/array-bounds
arm-none-eabi-gcc 14.3.1 (arm-gnu-toolchain-14.3.rel1) misdiagnoses the std::copy byte-transfer in integer_storage::integer_storage(T, endian) and to_integral() as overflowing when SIZE == 1, claiming a memmove of "between 2 and 2147483647 bytes" into a 1-byte destination. The copy count is always a compile-time constant bounded by min(sizeof(T), SIZE), so this is a compiler false positive, not a real overflow. Wrap the transfer logic in both functions with a GCC-only diagnostic push/pop that ignores -Wstringop-overflow and -Warray-bounds. Signed-off-by: Benedek Kupper <kupper.benedek@gmail.com>
1 parent 58bda56 commit 6b9c227

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

bitfilled/bitfilled/integer.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ struct integer_storage : public std::array<sized_unsigned_t<1>, SIZE>
8888
}
8989
#endif
9090
// transfer the bytes to the correct position
91+
#if defined(__GNUC__) && !defined(__clang__)
92+
#pragma GCC diagnostic push
93+
#pragma GCC diagnostic ignored "-Wstringop-overflow"
94+
#pragma GCC diagnostic ignored "-Warray-bounds"
95+
#endif
9196
constexpr long size_diff = (long)sizeof(T) - (long)SIZE;
9297
constexpr auto min_size = std::min(sizeof(T), SIZE);
9398
if (endianness == std::endian::little)
@@ -111,6 +116,9 @@ struct integer_storage : public std::array<sized_unsigned_t<1>, SIZE>
111116
this->data() - size_diff);
112117
}
113118
}
119+
#if defined(__GNUC__) && !defined(__clang__)
120+
#pragma GCC diagnostic pop
121+
#endif
114122
}
115123

116124
template <std::integral T>
@@ -126,6 +134,11 @@ struct integer_storage : public std::array<sized_unsigned_t<1>, SIZE>
126134
}
127135

128136
// transfer the bytes to the correct position
137+
#if defined(__GNUC__) && !defined(__clang__)
138+
#pragma GCC diagnostic push
139+
#pragma GCC diagnostic ignored "-Wstringop-overflow"
140+
#pragma GCC diagnostic ignored "-Warray-bounds"
141+
#endif
129142
constexpr long size_diff = (long)SIZE - (long)sizeof(T);
130143
constexpr auto min_size = std::min(sizeof(T), SIZE);
131144
if (endianness == std::endian::little)
@@ -148,6 +161,9 @@ struct integer_storage : public std::array<sized_unsigned_t<1>, SIZE>
148161
std::copy(this->data(), this->data() + SIZE, value_repr.data() - size_diff);
149162
}
150163
}
164+
#if defined(__GNUC__) && !defined(__clang__)
165+
#pragma GCC diagnostic pop
166+
#endif
151167

152168
// if not native endianness, reverse byte order
153169
#if !__cpp_lib_byteswap

0 commit comments

Comments
 (0)