- 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.

svn path=/trunk/; revision=17897
This commit is contained in:
Eric Kohl 2005-09-17 17:16:33 +00:00
parent d5f2eeedd7
commit 13fa268dc1

View file

@ -49,6 +49,8 @@ typedef struct _STRING_TABLE
DWORD dwMaxDataSize;
} STRING_TABLE, *PSTRING_TABLE;
WCHAR empty[] = {0};
/**************************************************************************
* StringTableInitialize [SETUPAPI.@]
@ -240,14 +242,14 @@ StringTableAddString(HSTRING_TABLE hStringTable,
{
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 @@ StringTableAddString(HSTRING_TABLE hStringTable,
pStringTable->dwUsedSlots++;
return i;
return i + 1;
}
}
@ -437,20 +439,20 @@ StringTableGetExtraData(HSTRING_TABLE hStringTable,
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 @@ StringTableLookUpString(HSTRING_TABLE hStringTable,
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 @@ StringTableSetExtraData(HSTRING_TABLE hStringTable,
return FALSE;
}
if (dwId >= pStringTable->dwMaxSlots)
if (dwId == 0 || dwId > pStringTable->dwMaxSlots)
{
ERR("Invalid Slot id!\n");
return FALSE;
@ -585,17 +587,17 @@ StringTableSetExtraData(HSTRING_TABLE hStringTable,
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 @@ StringTableStringFromId(HSTRING_TABLE hStringTable,
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 @@ StringTableStringFromIdEx(HSTRING_TABLE hStringTable,
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;
}