Why does replace() return the original string when the pattern is not found? #3
-
|
In Arimo's String.replace() method, when the old string is not found in the source, the method returns the original string unchanged instead of crashing. How is this handled at the LLVM IR level? For example: Is there a null check somewhere in the generated IR? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
The The fix adds a runtime null check in LLVM IR:
This gives correct behaviour without any Arimo-level changes. |
Beta Was this translation helpful? Give feedback.
The
strstrC function returns a null pointer when the pattern is not found. In the previous implementation this caused heap corruption becauseptr_to_int(null)produced 0, making the prefix length calculation overflow.The fix adds a runtime null check in LLVM IR:
strstris called and the result pointer is checked withbuild_is_null()rep.nofoundblock, jump torep.endrep.foundblock, do the replacement, jump torep.endrep.endselects between the originalstr_ptr(no match) and the newbuf_ptr(match found)This gives correct behaviour without any Arimo-level changes.