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

[Bug] std::string::replace truncates output, proportional to length of pattern #1279

Closed
1 task
bgilbert opened this issue Sep 2, 2023 · 5 comments
Closed
1 task
Labels
bug Something isn't working

Comments

@bgilbert
Copy link

bgilbert commented Sep 2, 2023

Operating System

Linux

What's the issue you encountered?

std::string::replace() removes len(pattern) - 1 characters from the end of its return value, regardless of whether the input string contains the pattern.

How can the issue be reproduced?

This pattern code:

std::print("{}", std::string::replace("abcdefg", "b", "z"));
std::print("{}", std::string::replace("abcdefg", "bc", "z"));
std::print("{}", std::string::replace("abcdefg", "bcd", "z"));
std::print("{}", std::string::replace("abcdefg", "x", "z"));
std::print("{}", std::string::replace("abcdefg", "xx", "z"));
std::print("{}", std::string::replace("abcdefg", "xxx", "z"));

produces:

I: azcdefg
I: azdef
I: aze
I: abcdefg
I: abcdef
I: abcde

ImHex Version

1.30.1

ImHex Build Type

  • Nightly or built from sources

Installation type

Fedora (imhex-1.30.1-3.fc38.x86_64)

Additional context?

No response

@bgilbert bgilbert added the bug Something isn't working label Sep 2, 2023
@paxcut
Copy link
Contributor

paxcut commented Sep 2, 2023

Thank you for reporting this bug. I submitted a pr in the imhex-patterns repo for this bug here you can either check the change there and add it or wait until it gets merged (if it gets merged that is) and added to this repo.

@bgilbert
Copy link
Author

It looks like the fix in WerWolv/ImHex-Patterns#157 was buggy. The test case now prints:

I: azcdefgf
I: azdefef
I: azedef
I: abcdefgf
I: abcdefef
I: abcdedef

@paxcut
Copy link
Contributor

paxcut commented Sep 10, 2023

thats very weird. I am sure it was right. Let me see and mahe sure I get it right this time

@paxcut
Copy link
Contributor

paxcut commented Sep 11, 2023

I found out what was wrong and how to fix it, somehow a +1 was turned into a -1.

Please also note that you don't need to wait until the changes I commit get merged to test them. The Pull Request contains all the code needed to be able to test the changes. You are welcome to post to the Pull Request at any time and not only when it gets merged. If you don't feel comfortable posting there you may also post here if the changes proposed don't fix the issue.
To be sure these are the results that I obtain when the -1 in the change is turned into a +1 which I believe are the correct ones.

I: azcdefg
I: azdefg
I: azefg
I: abcdefg
I: abcdefg
I: abcdefg
I: Pattern exited with code: 0
I: Evaluation took 0.0817567s

I apologize for any problems this issue may have caused. Thank you for taking the time to test and post the results of the tests.

@bgilbert
Copy link
Author

Fixed in WerWolv/ImHex-Patterns#163.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants