Fix conversions between char and int #211
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patch tries to fix some issues related to casting between int and char in the completion code. On systems where char is signed, the code used to consider it an error if the user pressed a character outside of the 0:127 range; with this patch, chars are casted to unsigned char before being casted to int, so valid characters are represented as the integers 0:255 instead of -127:128. On systems where char is unsigned, the error check after calling
completeLine
would never trigger, since a negative int would get mapped into the 0:255 range due to the cast. With this patch, the return value fromcompleteLine
is checked before it's casted to char.I noticed these issues due to a "comparison always false due to limited range of data type" warning when compiling for aarch64, where chars are unsigned. I don't know if there are other similar issues in the code, but I did a quick check by compiling with
-Wconversion
and looking at places where stuff is converted from or to 'char' and didn't find anything suspicious.