Browse Source

REVIEWED: `TextReplace()`, revert breaking change, needs to be reviewed again... -WIP-

pull/5459/head
Ray 1 week ago
parent
commit
95f72b162b
1 changed files with 12 additions and 5 deletions
  1. +12
    -5
      src/rtext.c

+ 12
- 5
src/rtext.c View File

@ -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;

Loading…
Cancel
Save