Skip to content

Commit 70bcefc

Browse files
committed
cdk: Disable false -Warray-bounds and -Wstringop-overflow warnings
1 parent ec88597 commit 70bcefc

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,10 @@ endif()
299299
if (CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 12.0)
300300
# Silence a warning produced by a regression in GCC 12.0 and newer
301301
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106199
302+
# Note: The stringop-overflow warnings are shown also during linking phase
303+
# (observed with GCC 14.2)
302304
add_compile_options(-Wno-stringop-overflow)
305+
add_link_options(-Wno-stringop-overflow)
303306
endif()
304307

305308

cdk/include/mysql/cdk/foundation/codec.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,14 @@ static size_t convert(bytes buf, T &val)
220220
/*
221221
If buf size is smaller than sizeof(T), convert 1,2,4 or 8 initial
222222
bytes from the buffer: as much as fits into T.
223+
224+
Note: We check here that buffer size is big enough to store given amount
225+
of bytes but compilers still complain under -Warray-bounds (seen on
226+
Solaris with gcc 11.4).
223227
*/
224228

229+
PUSH_ARRAY_BOUNDS_WARNING_CDK
230+
225231
if (buf.size() >= sizeof(T))
226232
{
227233
val= *(T*)buf.begin();
@@ -252,6 +258,8 @@ static size_t convert(bytes buf, T &val)
252258
return 1;
253259
}
254260

261+
POP_ARRAY_BOUNDS_WARNING_CDK
262+
255263
// TODO: better error description
256264
throw_error(cdkerrc::conversion_error,
257265
"Number_codec: no data for conversion");

cdk/include/mysql/cdk/foundation/common.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#define DIAGNOSTIC_PUSH_CDK PRAGMA_CDK(warning (push))
4343
#define DIAGNOSTIC_POP_CDK PRAGMA_CDK(warning (pop))
4444

45-
#elif defined __GNUC__ || defined __clang__
45+
#elif defined __GNUC__ || defined __clang__
4646

4747
#define PRAGMA_CDK(X) _Pragma(#X)
4848
#define DISABLE_WARNING_CDK(W) PRAGMA_CDK(GCC diagnostic ignored #W)
@@ -113,6 +113,25 @@
113113
#define POP_SYS_WARNINGS_CDK DIAGNOSTIC_POP_CDK
114114

115115

116+
/*
117+
Macros to disable false positives from -Warray-bounds checks for lines
118+
of code that were manually verified to be correct.
119+
*/
120+
121+
#ifdef _MSC_VER
122+
123+
#define PUSH_ARRAY_BOUNDS_WARNING_CDK DIAGNOSTIC_PUSH_CDK
124+
#define POP_ARRAY_BOUNDS_WARNING_CDK DIAGNOSTIC_POP_CDK
125+
126+
#else
127+
128+
#define PUSH_ARRAY_BOUNDS_WARNING_CDK \
129+
DIAGNOSTIC_PUSH_CDK DISABLE_WARNING_CDK(-Warray-bounds)
130+
#define POP_ARRAY_BOUNDS_WARNING_CDK DIAGNOSTIC_POP_CDK
131+
132+
#endif
133+
134+
116135
// Avoid warnings from Protobuf includes
117136

118137
#if defined _MSC_VER

0 commit comments

Comments
 (0)