fix: fixes issue #2183.#2184
Conversation
Forgot to check for empty lines before trying to find first non-space char.
| auto home=0; | ||
| while (isspace(line[home].mChar)) | ||
| home++; | ||
| if (line.size() > 0) { |
There was a problem hiding this comment.
This doesn't fix the case where the line is non-empty but only has spaces. Something like while(home < line.size() && line[home]..) is probably the right fix here. 🙂
There was a problem hiding this comment.
What do you mean by not fixing that case? I tested that and it doesnt crash anymore. The way I understood the request to make the home key skip initial spaces is that the right answer should be the end of the string of spaces at the beginning of the line regardless of the existence of any characters following them. When the last space is found the cursor is placed after it and before the next line so that should work fine. The Home key can become equivalent to the end key in special cases like this just like the end key becomes equivalent to the home key in an empty line.
There was a problem hiding this comment.
Haven't tested if it crashes but I'd expect it to go out of bounds at the end of the line.
With a line of [' ', ' '] it'll increment home to 2 and then check line[2] which is should fail right?
There was a problem hiding this comment.
I cant test the latest version because Im in the process of compiling 150 files and it can take a while on my slow computer. While it is true that it seems like it should crash, I tested a line of spaces on an older version and it didn't crash so i assume it won't either in this one, but until i can debug it I can't really say why or even if it still works.
There was a problem hiding this comment.
Yes, you were right, but going out of bounds for a non-empty vector doesn't crash ImHex for some reason so i thought it was finding a new line or end of line char but there is nothing like that. I added the code you posted to the fix to commit in a bit when I finish what I'm currently doing. thanks for the help.
…s incomplete and didn't cover the case of a non-empty line made out of paces entirely. Although it looked like ot worked ok, under debugging it was apparent that it was reading a vector out of bounds which can cause memory corruption errors that cn be hard to track down. Implemented code suggested by the issue author and this seems to fix the problem completely. Thanks!
|
The changes in this PR are superseded by the changes in PR 2193 that implements all the changes proposed here. |
Fixes issue #2183 Find details there but basically I forgot to check for empty lines before trying to find first non-space char.