Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regexp_replace() returning incorrect pointer? #39

Closed
drjdpowell opened this issue Jun 15, 2022 · 3 comments
Closed

regexp_replace() returning incorrect pointer? #39

drjdpowell opened this issue Jun 15, 2022 · 3 comments

Comments

@drjdpowell
Copy link

drjdpowell commented Jun 15, 2022

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

@nalgeon
Copy link
Owner

nalgeon commented Jun 18, 2022

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
Copy link
Owner

nalgeon commented Aug 31, 2022

Found the bug and fixed it in 0.15.3.

@nalgeon nalgeon closed this as completed Aug 31, 2022
@drjdpowell
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants