("String Val", "A string value", REG_SZ),
("StringExpand", "The path is %path%", REG_EXPAND_SZ),
("Multi-string", ["Lots", "of", "string", "values"], REG_MULTI_SZ),
+ ("Multi-nul", ["", "", "", ""], REG_MULTI_SZ),
("Raw Data", b"binary\x00data", REG_BINARY),
("Big String", "x"*(2**14-1), REG_SZ),
("Big Binary", b"x"*(2**14), REG_BINARY),
int i;
wchar_t *Q;
- Q = data + len;
- for (P = data, i = 0; P < Q && *P != '\0'; P++, i++) {
+ if (len > 0 && data[len - 1] == '\0') {
+ Q = data + len - 1;
+ }
+ else {
+ Q = data + len;
+ }
+
+ for (P = data, i = 0; P < Q; P++, i++) {
str[i] = P;
- for (; P < Q && *P != '\0'; P++)
+ for (; P < Q && *P != '\0'; P++) {
;
+ }
}
}
countStrings(wchar_t *data, int len)
{
int strings;
- wchar_t *P;
- wchar_t *Q = data + len;
+ wchar_t *P, *Q;
+
+ if (len > 0 && data[len - 1] == '\0') {
+ Q = data + len - 1;
+ }
+ else {
+ Q = data + len;
+ }
- for (P = data, strings = 0; P < Q && *P != '\0'; P++, strings++)
- for (; P < Q && *P != '\0'; P++)
+ for (P = data, strings = 0; P < Q; P++, strings++) {
+ for (; P < Q && *P != '\0'; P++) {
;
+ }
+ }
return strings;
}
}
for (index = 0; index < s; index++)
{
- size_t len = wcslen(str[index]);
- if (len > INT_MAX) {
- PyErr_SetString(PyExc_OverflowError,
- "registry string is too long for a Python string");
- Py_DECREF(obData);
- PyMem_Free(str);
- return NULL;
- }
- PyObject *uni = PyUnicode_FromWideChar(str[index], len);
+ size_t slen = wcsnlen(str[index], len);
+ PyObject *uni = PyUnicode_FromWideChar(str[index], slen);
if (uni == NULL) {
Py_DECREF(obData);
PyMem_Free(str);
return NULL;
}
PyList_SET_ITEM(obData, index, uni);
+ len -= slen + 1;
}
PyMem_Free(str);