mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-28 07:18:30 +00:00
free replacement string
replacement string needs one more byte also
This commit is contained in:
parent
3a67dd0b31
commit
f5acfbab44
1 changed files with 4 additions and 3 deletions
|
@ -404,16 +404,17 @@ static void OpenInput(const char *path) {
|
||||||
|
|
||||||
static void ReplaceString(struct Param *param) {
|
static void ReplaceString(struct Param *param) {
|
||||||
Elf64_Xword len = strnlen(param->roloc, roend - param->roloc);
|
Elf64_Xword len = strnlen(param->roloc, roend - param->roloc);
|
||||||
char *targstr = Malloc(len);
|
char *targstr = Malloc(len + 1);
|
||||||
for (Elf64_Xword i = 0; i < len; ++i)
|
for (Elf64_Xword i = 0; i < len + 1; ++i)
|
||||||
targstr[i] = 0;
|
targstr[i] = 0;
|
||||||
strcat(targstr, param->to_string);
|
strcpy(targstr, param->to_string);
|
||||||
strcat(targstr, param->roloc + param->from_len);
|
strcat(targstr, param->roloc + param->from_len);
|
||||||
#ifdef MODE_DBG
|
#ifdef MODE_DBG
|
||||||
kprintf("'%s' should be '%s'\n", param->roloc, targstr);
|
kprintf("'%s' should be '%s'\n", param->roloc, targstr);
|
||||||
#endif
|
#endif
|
||||||
strcpy(param->roloc, targstr);
|
strcpy(param->roloc, targstr);
|
||||||
param->roloc += len;
|
param->roloc += len;
|
||||||
|
free(targstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue