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

This commit is contained in:
Joseph Lee 2008-04-08 23:37:22 +00:00
parent c4b12b18cb
commit 543a6a3a7e

View File

@ -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);
}