Browse Source

don't decrement zero-length REG_*SZ strings passed back from the registry

Joseph Lee 17 years ago
parent
commit
543a6a3a7e
1 changed files with 6 additions and 4 deletions
  1. 6 4
      panda/src/express/windowsRegistry.cxx

+ 6 - 4
panda/src/express/windowsRegistry.cxx

@@ -304,8 +304,9 @@ do_get(const string &key, const string &name, int &data_type, string &data,
     if (data_type == REG_SZ || 
         data_type == REG_MULTI_SZ || 
         data_type == REG_EXPAND_SZ) {
-      // Eliminate the trailing null character.
-      buffer_size--;
+      // Eliminate the trailing null character for non-zero lengths.
+      if (buffer_size > 0)              // if zero, leave it
+        buffer_size--;
     }
     data = string(init_buffer, buffer_size);
 
@@ -325,8 +326,9 @@ do_get(const string &key, const string &name, int &data_type, string &data,
       if (data_type == REG_SZ || 
           data_type == REG_MULTI_SZ || 
           data_type == REG_EXPAND_SZ) {
-        // Eliminate the trailing null character.
-        buffer_size--;
+        // Eliminate the trailing null character for non-zero lengths.
+        if (buffer_size > 0)            // if zero, leave it
+          buffer_size--;
       }
       data = string(new_buffer, buffer_size);
     }