[libzomg] Metadata_win32.cpp::getUserName_ansi(): Only check for NULLs if cbUsername...
authorDavid Korth <gerbilsoft@gerbilsoft.com>
Sun, 3 Apr 2016 05:35:53 +0000 (01:35 -0400)
committerDavid Korth <gerbilsoft@gerbilsoft.com>
Sun, 3 Apr 2016 05:35:53 +0000 (01:35 -0400)
Found using cppcheck-1.72.

src/libzomg/Metadata_win32.cpp

index 9489755..137cd83 100644 (file)
@@ -188,13 +188,13 @@ static string getUserName_ansi(void)
                cbUsername = 0;
        }
 
-       // Remove any trailing NULL bytes.
-       if (username[cbUsername-1] == 0) {
-               // Found a trailing NULL byte.
-               cbUsername--;
-       }
-
        if (cbUsername > 0) {
+               // Remove any trailing NULL bytes.
+               if (username[cbUsername-1] == 0) {
+                       // Found a trailing NULL byte.
+                       cbUsername--;
+               }
+
                // Try to convert from ANSI to UTF-8.
                // FIXME: If this fails, use the ANSI text as-is?