From: PatR Date: Thu, 5 Nov 2020 22:28:17 +0000 (-0800) Subject: Qt str_copy() X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=702e52b43112f47413def1408e0d42a72a8302ef;p=nethack Qt str_copy() The Qt interface's routine to perform a bounded string copy ignored the limit when copying and only honored the limit to lie about the return length. --- diff --git a/win/Qt/qt_str.cpp b/win/Qt/qt_str.cpp index 9450bd895..1a6de3f90 100644 --- a/win/Qt/qt_str.cpp +++ b/win/Qt/qt_str.cpp @@ -13,14 +13,14 @@ namespace nethack_qt_ { // Bounded string copy size_t str_copy(char *dest, const char *src, size_t max) { - size_t len = strlen(src); + size_t len = 0; if (max != 0) { - size_t csize = len; + len = strlen(src); if (len > max - 1) { len = max - 1; } - memcpy(dest, src, csize); - dest[csize] = '\0'; + memcpy(dest, src, len); + dest[len] = '\0'; } return len; }