sqlean icon indicating copy to clipboard operation
sqlean copied to clipboard

regexp_replace() returning incorrect pointer?

Open drjdpowell opened this issue 2 years ago • 1 comments

Hello, I am trying to use the re extension for RegEx (on Windows, compiling for 32-bit). Functions all work, except for the regexp_replace function. It returns correctly when it doesn't find anything to replace, but there is a strange effect when something is replaced:

My Test case is select regexp_replace('The current year is AD 2025', '[0-9]+', '2050')

The result varies on each call. For example, here are ten calls: mainThe current year is AD sqlThe current year is AD 2 The current year is AD 2050 The current year is AD 2050 sqlite_masterThe current ye tbl_name='AAA' AND type!='t mainThe current year is AD sqlite_masterThe current ye The current year is AD 2050 TEXTThe current year is AD

It behaves as if the call I make to sqlite_column_text() returns a pointer that is a variable number of bytes smaller than the actual start of the result string. I thus read some other bit of memory before the actual value starts, and loss the end of the value (I copy a number of bytes returned by sqlite3_column_bytes()).

Any ideas of what might be wrong?

-- James Powell

drjdpowell avatar Jun 15 '22 10:06 drjdpowell

Thanks for noticing! Unfortunately, I don't have a Windows machine to check this issue. Will look into it when I have a chance.

The source code for the regexp_replace() function looks pretty awful, but it passes the tests on Linux / macOS.

nalgeon avatar Jun 18 '22 15:06 nalgeon

Found the bug and fixed it in 0.15.3.

nalgeon avatar Aug 31 '22 14:08 nalgeon

Thanks!

drjdpowell avatar Nov 23 '22 10:11 drjdpowell