Skip to content

Commit dc6d8b4

Browse files
committed
Fix false positive -Wstringop-overread warning in GCC
1 parent 836d4eb commit dc6d8b4

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
- Add support for `void*` formatting ([#759](https://github.com/odygrd/quill/issues/759))
9494
- Fix a bug in `RotatingJsonFileSink.h` where file size-based rotation wasn't triggering
9595
properly ([#767](https://github.com/odygrd/quill/issues/767))
96+
- Fix false positive `-Wstringop-overread` warning in GCC ([#766](https://github.com/odygrd/quill/issues/766))
9697

9798
## v9.0.2
9899

include/quill/core/Codec.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,20 @@ QUILL_NODISCARD inline size_t safe_strnlen(char const* str, size_t maxlen) noexc
9494
return 0;
9595
}
9696

97+
#if defined(__GNUC__) && !defined(__clang__)
98+
// Suppress false positive in GCC - memchr safely stops at null terminator
99+
#pragma GCC diagnostic push
100+
#if __GNUC__ >= 13
101+
#pragma GCC diagnostic ignored "-Wstringop-overread"
102+
#endif
103+
#endif
104+
97105
auto end = static_cast<char const*>(std::memchr(str, '\0', maxlen));
106+
107+
#if defined(__GNUC__) && !defined(__clang__)
108+
#pragma GCC diagnostic pop
109+
#endif
110+
98111
return end ? static_cast<size_t>(end - str) : maxlen;
99112
}
100113

0 commit comments

Comments
 (0)