diff --git a/panda/src/express/windowsRegistry.cxx b/panda/src/express/windowsRegistry.cxx index 7185b238d2..239737c214 100755 --- a/panda/src/express/windowsRegistry.cxx +++ b/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); }