free replacement string

replacement string needs one more byte also
This commit is contained in:
Gautham 2024-12-27 22:23:39 -06:00
parent 3a67dd0b31
commit f5acfbab44

View file

@ -404,16 +404,17 @@ static void OpenInput(const char *path) {
static void ReplaceString(struct Param *param) {
Elf64_Xword len = strnlen(param->roloc, roend - param->roloc);
char *targstr = Malloc(len);
for (Elf64_Xword i = 0; i < len; ++i)
char *targstr = Malloc(len + 1);
for (Elf64_Xword i = 0; i < len + 1; ++i)
targstr[i] = 0;
strcat(targstr, param->to_string);
strcpy(targstr, param->to_string);
strcat(targstr, param->roloc + param->from_len);
#ifdef MODE_DBG
kprintf("'%s' should be '%s'\n", param->roloc, targstr);
#endif
strcpy(param->roloc, targstr);
param->roloc += len;
free(targstr);
}
int main(int argc, char *argv[]) {