summaryrefslogtreecommitdiffstats
path: root/win/tclWinReg.c
diff options
context:
space:
mode:
authorstanton <stanton>1998-06-18 18:26:50 (GMT)
committerstanton <stanton>1998-06-18 18:26:50 (GMT)
commit9c26160ec54ce1abcd3f8590cbc8e9ad30fcc9d8 (patch)
tree756937b2e64032bb663b8f8c7563b155eada5a1d /win/tclWinReg.c
parente27be7921a7f70adf89b0c59b976c96c32fae7a8 (diff)
downloadtcl-9c26160ec54ce1abcd3f8590cbc8e9ad30fcc9d8.zip
tcl-9c26160ec54ce1abcd3f8590cbc8e9ad30fcc9d8.tar.gz
tcl-9c26160ec54ce1abcd3f8590cbc8e9ad30fcc9d8.tar.bz2
fixed bad array bounds checks
added performance boost for small values
Diffstat (limited to 'win/tclWinReg.c')
-rw-r--r--win/tclWinReg.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/win/tclWinReg.c b/win/tclWinReg.c
index 5e5d450..d2bd014 100644
--- a/win/tclWinReg.c
+++ b/win/tclWinReg.c
@@ -79,7 +79,7 @@ static char *typeNames[] = {
"dword_big_endian", "link", "multi_sz", "resource_list", NULL
};
-static DWORD lastType = REG_RESOURCE_REQUIREMENTS_LIST;
+static DWORD lastType = REG_RESOURCE_LIST;
/*
@@ -542,7 +542,7 @@ GetType(
* If we don't know about the type, just use the numeric value.
*/
- if (type > lastType) {
+ if (type > lastType || type < 0) {
Tcl_SetIntObj(resultPtr, type);
} else {
Tcl_SetStringObj(resultPtr, typeNames[type], -1);
@@ -590,19 +590,27 @@ GetValue(
}
/*
- * Get the value once to determine the length then again to store
- * the data in the buffer.
+ * Initialize a Dstring to maximum statically allocated size
+ * we could get one more byte by avoiding Tcl_DStringSetLength()
+ * and just setting length to TCL_DSTRING_STATIC_SIZE, but this
+ * should be safer if the implementation Dstrings changes.
+ *
+ * This allows short values to be read from the registy in one call.
+ * Longer values need a second call with an expanded DString.
*/
Tcl_DStringInit(&data);
- resultPtr = Tcl_GetObjResult(interp);
+ Tcl_DStringSetLength(&data, length = TCL_DSTRING_STATIC_SIZE - 1);
- valueName = Tcl_GetStringFromObj(valueNameObj, (int*) &length);
- result = RegQueryValueEx(key, valueName, NULL, &type, NULL, &length);
- if (result == ERROR_SUCCESS) {
- Tcl_DStringSetLength(&data, length);
- result = RegQueryValueEx(key, valueName, NULL, &type,
- (LPBYTE) Tcl_DStringValue(&data), &length);
+ resultPtr = Tcl_GetObjResult(interp);
+
+ valueName = Tcl_GetStringFromObj(valueNameObj, NULL);
+ result = RegQueryValueEx(key, valueName, NULL, &type,
+ (LPBYTE) Tcl_DStringValue(&data), &length);
+ if (result == ERROR_MORE_DATA) {
+ Tcl_DStringSetLength(&data, length);
+ result = RegQueryValueEx(key, valueName, NULL, &type,
+ (LPBYTE) Tcl_DStringValue(&data), &length);
}
RegCloseKey(key);
if (result != ERROR_SUCCESS) {