- String id 0 becomes a reserved (invalid) id.
- StringTableStringFromId returns a pointer to an empty string if the string id is invalid.
This commit is contained in:
parent
882023b2fa
commit
da46628883
|
@ -239,14 +239,14 @@ StringTableAddString(HSTRING_TABLE hStringTable,
|
||||||
{
|
{
|
||||||
if (!lstrcmpW(pStringTable->pSlots[i].pString, lpString))
|
if (!lstrcmpW(pStringTable->pSlots[i].pString, lpString))
|
||||||
{
|
{
|
||||||
return i;
|
return i + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!lstrcmpiW(pStringTable->pSlots[i].pString, lpString))
|
if (!lstrcmpiW(pStringTable->pSlots[i].pString, lpString))
|
||||||
{
|
{
|
||||||
return i;
|
return i + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -275,7 +275,7 @@ StringTableAddString(HSTRING_TABLE hStringTable,
|
||||||
|
|
||||||
pStringTable->dwUsedSlots++;
|
pStringTable->dwUsedSlots++;
|
||||||
|
|
||||||
return i;
|
return i + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -436,20 +436,20 @@ StringTableGetExtraData(HSTRING_TABLE hStringTable,
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dwId >= pStringTable->dwMaxSlots)
|
if (dwId == 0 || dwId > pStringTable->dwMaxSlots)
|
||||||
{
|
{
|
||||||
ERR("Invalid Slot id!\n");
|
ERR("Invalid Slot id!\n");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pStringTable->pSlots[dwId].dwSize < dwExtraDataSize)
|
if (pStringTable->pSlots[dwId - 1].dwSize < dwExtraDataSize)
|
||||||
{
|
{
|
||||||
ERR("Data size is too large!\n");
|
ERR("Data size is too large!\n");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(lpExtraData,
|
memcpy(lpExtraData,
|
||||||
pStringTable->pSlots[dwId].pData,
|
pStringTable->pSlots[dwId - 1].pData,
|
||||||
dwExtraDataSize);
|
dwExtraDataSize);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -496,12 +496,12 @@ StringTableLookUpString(HSTRING_TABLE hStringTable,
|
||||||
if (dwFlags & 1)
|
if (dwFlags & 1)
|
||||||
{
|
{
|
||||||
if (!lstrcmpW(pStringTable->pSlots[i].pString, lpString))
|
if (!lstrcmpW(pStringTable->pSlots[i].pString, lpString))
|
||||||
return i;
|
return i + 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!lstrcmpiW(pStringTable->pSlots[i].pString, lpString))
|
if (!lstrcmpiW(pStringTable->pSlots[i].pString, lpString))
|
||||||
return i;
|
return i + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -572,7 +572,7 @@ StringTableSetExtraData(HSTRING_TABLE hStringTable,
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dwId >= pStringTable->dwMaxSlots)
|
if (dwId == 0 || dwId > pStringTable->dwMaxSlots)
|
||||||
{
|
{
|
||||||
ERR("Invalid Slot id!\n");
|
ERR("Invalid Slot id!\n");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -584,17 +584,17 @@ StringTableSetExtraData(HSTRING_TABLE hStringTable,
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
pStringTable->pSlots[dwId].pData = MyMalloc(dwExtraDataSize);
|
pStringTable->pSlots[dwId - 1].pData = MyMalloc(dwExtraDataSize);
|
||||||
if (pStringTable->pSlots[dwId].pData == NULL)
|
if (pStringTable->pSlots[dwId - 1].pData == NULL)
|
||||||
{
|
{
|
||||||
ERR("\n");
|
ERR("\n");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(pStringTable->pSlots[dwId].pData,
|
memcpy(pStringTable->pSlots[dwId - 1].pData,
|
||||||
lpExtraData,
|
lpExtraData,
|
||||||
dwExtraDataSize);
|
dwExtraDataSize);
|
||||||
pStringTable->pSlots[dwId].dwSize = dwExtraDataSize;
|
pStringTable->pSlots[dwId - 1].dwSize = dwExtraDataSize;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -618,6 +618,7 @@ StringTableStringFromId(HSTRING_TABLE hStringTable,
|
||||||
DWORD dwId)
|
DWORD dwId)
|
||||||
{
|
{
|
||||||
PSTRING_TABLE pStringTable;
|
PSTRING_TABLE pStringTable;
|
||||||
|
static WCHAR empty[] = {0};
|
||||||
|
|
||||||
TRACE("%p %lx\n", hStringTable, dwId);
|
TRACE("%p %lx\n", hStringTable, dwId);
|
||||||
|
|
||||||
|
@ -628,10 +629,10 @@ StringTableStringFromId(HSTRING_TABLE hStringTable,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dwId >= pStringTable->dwMaxSlots)
|
if (dwId == 0 || dwId > pStringTable->dwMaxSlots)
|
||||||
return NULL;
|
return empty;
|
||||||
|
|
||||||
return pStringTable->pSlots[dwId].pString;
|
return pStringTable->pSlots[dwId - 1].pString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -670,18 +671,18 @@ StringTableStringFromIdEx(HSTRING_TABLE hStringTable,
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dwId >= pStringTable->dwMaxSlots ||
|
if (dwId == 0 || dwId > pStringTable->dwMaxSlots ||
|
||||||
pStringTable->pSlots[dwId].pString == NULL)
|
pStringTable->pSlots[dwId - 1].pString == NULL)
|
||||||
{
|
{
|
||||||
WARN("Invalid string ID!\n");
|
WARN("Invalid string ID!\n");
|
||||||
*lpBufferLength = 0;
|
*lpBufferLength = 0;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
dwLength = (lstrlenW(pStringTable->pSlots[dwId].pString) + 1) * sizeof(WCHAR);
|
dwLength = (lstrlenW(pStringTable->pSlots[dwId - 1].pString) + 1) * sizeof(WCHAR);
|
||||||
if (dwLength <= *lpBufferLength)
|
if (dwLength <= *lpBufferLength)
|
||||||
{
|
{
|
||||||
lstrcpyW(lpBuffer, pStringTable->pSlots[dwId].pString);
|
lstrcpyW(lpBuffer, pStringTable->pSlots[dwId - 1].pString);
|
||||||
bResult = TRUE;
|
bResult = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -122,15 +122,14 @@ static void test_StringTableStringFromId(void)
|
||||||
ok(string2!=NULL,"Failed to look up string by ID from String Table\n");
|
ok(string2!=NULL,"Failed to look up string by ID from String Table\n");
|
||||||
|
|
||||||
result=lstrcmpiW(string, string2);
|
result=lstrcmpiW(string, string2);
|
||||||
ok(result==0,"String %p does not match requested StringID %p\n",string,string2);
|
ok(result==0,"StringID %p does not match requested StringID %p\n",string,string2);
|
||||||
|
|
||||||
|
/* This should never work */
|
||||||
string3=pStringTableStringFromId(table,0);
|
string3=pStringTableStringFromId(table,0);
|
||||||
ok(string3!=NULL,"Failed to look up string by ID from String Table\n");
|
ok(string3!=NULL,"Failed to look up string by ID from String Table\n");
|
||||||
|
|
||||||
todo_wine {
|
result=lstrcmpiW(string, string3);
|
||||||
result=lstrcmpiW(string, string3);
|
ok(result!=0,"StringID %p matches requested StringID %p\n",string,string3);
|
||||||
ok(result!=0,"String %p does not match requested StringID %p\n",string,string2);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
START_TEST(stringtable)
|
START_TEST(stringtable)
|
||||||
|
|
Loading…
Reference in New Issue