Skip to content
Discussion options

You must be logged in to vote

The strstr C function returns a null pointer when the pattern is not found. In the previous implementation this caused heap corruption because ptr_to_int(null) produced 0, making the prefix length calculation overflow.

The fix adds a runtime null check in LLVM IR:

  1. strstr is called and the result pointer is checked with build_is_null()
  2. If null → branch to rep.nofound block, jump to rep.end
  3. If non-null → branch to rep.found block, do the replacement, jump to rep.end
  4. A phi node at rep.end selects between the original str_ptr (no match) and the new buf_ptr (match found)

This gives correct behaviour without any Arimo-level changes.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by egecanakincioglu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant