Fix GetCodepointNext to return default value with size=0 on invalid input. Modify LoadCodepoints to work when GetCodepointNext returns a size of 0. All internal use of GetCodepointNext and GetCodepointPrev checked. This fix may break external code dealing with invalid input as the old code erroneously never returned a size of 0, external code that doesn't properly check for size=0 may endlessly loop or overflow a buffer on invalid input.
This commit is contained in:
parent
17c443ee6d
commit
fb89eac7dc
|
|
@ -1704,7 +1704,9 @@ int *LoadCodepoints(const char *text, int *count)
|
|||
for (int i = 0; i < textLength; codepointCount++)
|
||||
{
|
||||
codepoints[codepointCount] = GetCodepointNext(text + i, &codepointSize);
|
||||
i += codepointSize;
|
||||
|
||||
if (codepoints[codepointCount] == 0x3f) i += 1;
|
||||
else i += codepointSize;
|
||||
}
|
||||
|
||||
// Re-allocate buffer to the actual number of codepoints loaded
|
||||
|
|
@ -1917,7 +1919,7 @@ int GetCodepointNext(const char *text, int *codepointSize)
|
|||
codepoint = ((0x1f & ptr[0]) << 6) | (0x3f & ptr[1]);
|
||||
*codepointSize = 2;
|
||||
}
|
||||
else
|
||||
else if (0x00 == (0x80 & ptr[0]))
|
||||
{
|
||||
// 1 byte UTF-8 codepoint
|
||||
codepoint = ptr[0];
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user