- String id 0 becomes a reserved (invalid) id. - StringTableStringFromId returns a pointer to an empty string if the string id is invalid. This fixes the stringtable tests. Modified: trunk/reactos/lib/setupapi/stringtable.c _____
Modified: trunk/reactos/lib/setupapi/stringtable.c --- trunk/reactos/lib/setupapi/stringtable.c 2005-09-17 16:02:37 UTC (rev 17896) +++ trunk/reactos/lib/setupapi/stringtable.c 2005-09-17 17:16:33 UTC (rev 17897) @@ -49,7 +49,9 @@
DWORD dwMaxDataSize; } STRING_TABLE, *PSTRING_TABLE;
+WCHAR empty[] = {0};
+
/*********************************************************************** *** * StringTableInitialize [SETUPAPI.@] * @@ -240,14 +242,14 @@ { if (!lstrcmpW(pStringTable->pSlots[i].pString, lpString)) { - return i; + return i + 1; } } else { if (!lstrcmpiW(pStringTable->pSlots[i].pString, lpString)) { - return i; + return i + 1; } } } @@ -276,7 +278,7 @@
pStringTable->dwUsedSlots++;
- return i; + return i + 1; } }
@@ -437,20 +439,20 @@ return FALSE; }
- if (dwId >= pStringTable->dwMaxSlots) + if (dwId == 0 || dwId > pStringTable->dwMaxSlots) { ERR("Invalid Slot id!\n"); return FALSE; }
- if (pStringTable->pSlots[dwId].dwSize < dwExtraDataSize) + if (pStringTable->pSlots[dwId - 1].dwSize < dwExtraDataSize) { ERR("Data size is too large!\n"); return FALSE; }
memcpy(lpExtraData, - pStringTable->pSlots[dwId].pData, + pStringTable->pSlots[dwId - 1].pData, dwExtraDataSize);
return TRUE; @@ -497,12 +499,12 @@ if (dwFlags & 1) { if (!lstrcmpW(pStringTable->pSlots[i].pString, lpString)) - return i; + return i + 1; } else { if (!lstrcmpiW(pStringTable->pSlots[i].pString, lpString)) - return i; + return i + 1; } } } @@ -573,7 +575,7 @@ return FALSE; }
- if (dwId >= pStringTable->dwMaxSlots) + if (dwId == 0 || dwId > pStringTable->dwMaxSlots) { ERR("Invalid Slot id!\n"); return FALSE; @@ -585,17 +587,17 @@ return FALSE; }
- pStringTable->pSlots[dwId].pData = MyMalloc(dwExtraDataSize); - if (pStringTable->pSlots[dwId].pData == NULL) + pStringTable->pSlots[dwId - 1].pData = MyMalloc(dwExtraDataSize); + if (pStringTable->pSlots[dwId - 1].pData == NULL) { ERR("\n"); return FALSE; }
- memcpy(pStringTable->pSlots[dwId].pData, + memcpy(pStringTable->pSlots[dwId - 1].pData, lpExtraData, dwExtraDataSize); - pStringTable->pSlots[dwId].dwSize = dwExtraDataSize; + pStringTable->pSlots[dwId - 1].dwSize = dwExtraDataSize;
return TRUE; } @@ -629,10 +631,10 @@ return NULL; }
- if (dwId >= pStringTable->dwMaxSlots) - return NULL; + if (dwId == 0 || dwId > pStringTable->dwMaxSlots) + return empty;
- return pStringTable->pSlots[dwId].pString; + return pStringTable->pSlots[dwId - 1].pString; }
@@ -672,18 +674,18 @@ return FALSE; }
- if (dwId >= pStringTable->dwMaxSlots || - pStringTable->pSlots[dwId].pString == NULL) + if (dwId == 0 || dwId > pStringTable->dwMaxSlots || + pStringTable->pSlots[dwId - 1].pString == NULL) { WARN("Invalid string ID!\n"); *lpBufferLength = 0; return FALSE; }
- dwLength = (lstrlenW(pStringTable->pSlots[dwId].pString) + 1) * sizeof(WCHAR); + dwLength = (lstrlenW(pStringTable->pSlots[dwId - 1].pString) + 1) * sizeof(WCHAR); if (dwLength <= *lpBufferLength) { - lstrcpyW(lpBuffer, pStringTable->pSlots[dwId].pString); + lstrcpyW(lpBuffer, pStringTable->pSlots[dwId - 1].pString); bResult = TRUE; }