From c93c346adcd0f7cb443f6e8307aed6ccb59637af Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 6 Dec 2022 01:53:06 +0100 Subject: [PATCH] Don't append extra NUL to URLs in wxGTK wxURLDataObject The buffer size includes the trailing NUL, but we shouldn't make it part of the string contents as it's not really part of the data at all. The next commit will add a test verifying that retrieving an URL from clipboard now gets the right string, without an extra trailing NUL, i.e. fixes a bug similar to #22928 but in wxGTK. --- src/gtk/dataobj.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/gtk/dataobj.cpp b/src/gtk/dataobj.cpp index f5a0a43b68..9f54679115 100644 --- a/src/gtk/dataobj.cpp +++ b/src/gtk/dataobj.cpp @@ -438,6 +438,12 @@ public: { const char* const src = static_cast(buf); + // Length here includes the trailing NUL, but we don't want to include + // it into the string contents. + wxCHECK_MSG( len != 0 && !src[len], false, "must have trailing NUL" ); + + len--; + // The string might be "\r\n"-terminated but this is not necessarily // the case (e.g. when dragging an URL from Firefox, it isn't). if ( len > 1 && src[len - 1] == '\n' )