From d04dd7a44300d2feec341d97d789a935bed24fa9 Mon Sep 17 00:00:00 2001 From: Evgeniy Patlan Date: Fri, 6 Nov 2026 13:53:34 +0200 Subject: [PATCH] Fix stringop-overflow error in linenoise-ng under LTO The Ubuntu 24.04 deb build fails when linking mysqlsh with the default dpkg-buildflags (-flto=auto): ext/linenoise-ng/src/linenoise.cpp:462:11: error: '__builtin___memcpy_chk' writing 18446744073709551612 bytes into a region of size between 8 and 9223372036854775800 [-Werror=stringop-overflow=] The -Wno-stringop-overflow passed at compile time does not apply to the LTO link step, where the warning is turned into an error by -Werror. Utf32String::operator= allocated that._length elements but then copied that._length elements into the buffer and left no room for the terminating NUL, unlike the copy constructor and every other constructor, which allocate _length + 1. Once DisplayPrompt:: updateSearchText() is inlined, GCC cannot prove the allocation size matches the copy size and reports the copy as an overflow. Allocate _length + 1 in operator=, as the copy constructor does. This also makes the copied string NUL-terminated, as callers of get() expect. No warning flags are changed. --- ext/linenoise-ng/src/linenoise.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/linenoise-ng/src/linenoise.cpp b/ext/linenoise-ng/src/linenoise.cpp index ea8ce6565..bbf1db46e 100644 --- a/ext/linenoise-ng/src/linenoise.cpp +++ b/ext/linenoise-ng/src/linenoise.cpp @@ -484,7 +484,7 @@ class Utf32String { Utf32String &operator=(const Utf32String &that) { if (this != &that) { delete[] _data; - _data = new char32_t[that._length](); + _data = new char32_t[that._length + 1](); _length = that._length; memcpy(_data, that._data, sizeof(char32_t) * _length); }