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] Shift+Tab crashes on empty lines #1621

Open
1 task
ZwipZwapZapony opened this issue Mar 29, 2024 · 2 comments
Open
1 task

[Bug] Shift+Tab crashes on empty lines #1621

ZwipZwapZapony opened this issue Mar 29, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@ZwipZwapZapony
Copy link

Operating System

Windows

What's the issue you encountered?

In the Pattern Editor, pressing Tab inserts (up to) four spaces to indent a line, and pressing Shift+Tab removes (up to) four spaces to un-indent a line. If the text cursor is on a completely empty line, pressing Shift+Tab crashes ImHex.

How can the issue be reproduced?

In the Pattern Editor, move the text cursor to an empty line, and press Shift+Tab.

ImHex Version

v1.33.2

ImHex Build Type

  • Nightly or built from sources

Installation type

Portable zip from the GitHub Releases page

Additional context?

No response

@ZwipZwapZapony ZwipZwapZapony added the bug Something isn't working label Mar 29, 2024
@Calcoph
Copy link

Calcoph commented Apr 28, 2024

This doesn't happen on empty lines that are empty because the previous content was deleted. It only happens on newly created (unedited) empty lines

@paxcut
Copy link
Contributor

paxcut commented Apr 28, 2024

I traced the problem to this code in TextEditor.cpp

        auto spacesToRemove = (cindex % mTabSize);
            if (spacesToRemove == 0) spacesToRemove = 4;
            for (int32_t j = 0; j < spacesToRemove; j++) {
                if ((line.begin() + cindex - 1)->mChar == ' ') {
                    line.erase(line.begin() + cindex - 1);
                    cindex -= 1;
                }
            }

spacesToRemove is 4 and cindex is 0. line is size 0 so (line.begin()-1)->mChar segvs. A simple fix is to add this line before for loop

           spacesToRemove = std::min(spacesToRemove, (int32_t) line.size());

I tested it with lines with 0,1,2,3 and 4 spaces and it deletes the spaces if there are any and does nothing if line is empty. This will be included in my next text editor enhancements pr.

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

3 participants