Closed user202729 closed 7 months ago
@jlaurens Thanks for the quick fix, although the new code has the issue that -INT_MIN
(as written in the source code) will overflow and evaluate to INT_MIN
. Maybe better to just put INT_MAX
in both cases?
Speaking of which I think there are two issues with the synctex_merge_strings
function:
if(dest != strncpy(dest,temp,size))
this check does nothing, strncpy
always return dest
.result
is obtained from malloc(size)
, but if we include the null terminator, we need to malloc(size+1)
instead.Miscellaneous: on my machine, the compiler raises a warning like this
../synctex_parser_utils.c:370:52: warning: ‘strncpy’ output truncated before terminating nul copying
as many bytes from a string as its length [-Wstringop-truncation]
370 | if(dest != strncpy(dest,temp,size)) {
| ^~~~~~~~~~~~~~~~~~~~~~~
maybe it's better to make the intent explicit by using memcpy
instead. (I believe memcpy
should be faster as well because it doesn't need to check for null byte)
Proof of concept: https://github.com/user202729/luatex/commit/005c6702489d3a06dd3eca15ab4dbe8a7c544f0c
Admittedly this is ugly, but this part is very time-critical in the code.
In my testing, this change alone improves 17% performance (after applying the optimization described in #69 )
What do you think?
Caveat of the quick implementation above: