mirror of
https://github.com/raysan5/raylib.git
synced 2026-01-09 21:18:44 +01:00
REVIEWED: TextReplace(), revert breaking change, needs to be reviewed again... -WIP-
This commit is contained in:
17
src/rtext.c
17
src/rtext.c
@ -1746,16 +1746,23 @@ char *TextReplace(const char *text, const char *search, const char *replacement)
|
||||
{
|
||||
insertPoint = (char *)strstr(text, search);
|
||||
lastReplacePos = (int)(insertPoint - text);
|
||||
temp = strncpy(temp, text, tempLen - 1) + lastReplacePos;
|
||||
tempLen -= lastReplacePos;
|
||||
temp = strncpy(temp, replacement, tempLen - 1) + replaceLen;
|
||||
tempLen -= replaceLen;
|
||||
|
||||
// TODO: Review logic to avoid strcpy()
|
||||
// OK - Those lines work
|
||||
temp = strncpy(temp, text, lastReplacePos) + lastReplacePos;
|
||||
temp = strcpy(temp, replacement) + replaceLen;
|
||||
// WRONG - But not those ones
|
||||
//temp = strncpy(temp, text, tempLen - 1) + lastReplacePos;
|
||||
//tempLen -= lastReplacePos;
|
||||
//temp = strncpy(temp, replacement, tempLen - 1) + replaceLen;
|
||||
//tempLen -= replaceLen;
|
||||
|
||||
text += lastReplacePos + searchLen; // Move to next "end of replace"
|
||||
}
|
||||
|
||||
// Copy remaind text part after replacement to result (pointed by moving temp)
|
||||
strncpy(temp, text, tempLen - 1);
|
||||
strcpy(temp, text); // OK
|
||||
//strncpy(temp, text, tempLen - 1); // WRONG
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user