]> granicus.if.org Git - nethack/commitdiff
Qt str_copy()
authorPatR <rankin@nethack.org>
Thu, 5 Nov 2020 22:28:17 +0000 (14:28 -0800)
committerPatR <rankin@nethack.org>
Thu, 5 Nov 2020 22:28:17 +0000 (14:28 -0800)
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.

win/Qt/qt_str.cpp

index 9450bd89502859e766eefeb79a7898e2e5b9e7bc..1a6de3f902b24778b48cd5cb94a76a6bd6cae069 100644 (file)
@@ -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;
 }