Avoid undefined behaviour in DOH Replace() function
If the source and replacement strings were the same length, the code was performing undefined pointer arithmetic involving a NULL pointer. I'm not aware of any observable effects of this in practice, but it's potentially problematic. It's detected by ubsan, for example when running `make check-python-test-suite`: DOH/string.c:839:4: runtime error: applying non-zero offset to non-null pointer 0x602000001558 produced null pointer SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior DOH/string.c:839:4 in
This commit is contained in:
parent
b018c32f9d
commit
975f8fcfdb
1 changed files with 3 additions and 1 deletions
|
|
@ -836,7 +836,9 @@ static int replace_simple(String *str, char *token, char *rep, int flags, int co
|
|||
memmove(t, s, (str->str + str->len) - s + 1);
|
||||
}
|
||||
} else {
|
||||
t += (c - s);
|
||||
if (c) {
|
||||
t += (c - s);
|
||||
}
|
||||
}
|
||||
s = c;
|
||||
ic--;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue