Wrap ctype.h functions to avoid array subscript warnings#2306
Merged
Conversation
Copy HTSlib's internal wrappers for interfaces in <ctype.h> into sam_utils.h (as it's widely included already) and use them on cases where the input has `char` type. Fixes "array subscript has type 'char'" warnings on platforms that still implement them as a macro around an array look-up. The ctype interface wrappers were originally authored by John Marshall in HTSlib commit fc9aeb6
Contributor
|
There are a couple more, which this PR doesn't fix.
Edit: approved on the other changes though. Thanks |
Need to cast to unsigned to ensure all possible values are +ve.
This function takes data from various sources that may not have been well-filtered for unexpected character values. It therefore needs to be able to handle them, at least to the extent of not producing undefined behaviour. Rename variable `c` to `chr` to make it easier to find. Change type of `chr` and `rb` to char, to match the type of the data sources they may be set from. Use toupper_c() wrapper due to the change of type above. In case char is signed, cast `rb` to uint8_t before using it to index seq_nt16_table. Similarly, cast `chr` to uint8_t before passing the value to tv->my_mvaddch() (which takes int) to ensure the result it always positive.
Avoids sign-conversion warnings should they be enabled.
char should be cast to uint8_t, not int, to prevent sign extension.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Copy HTSlib's internal wrappers for interfaces in
<ctype.h>intosam_utils.h(as it's widely included already) and use them on cases where the input haschartype. Fixes "array subscript has type 'char'" warnings on platforms that still implement them as a macro around an array look-up.The ctype interface wrappers were originally authored by John Marshall in HTSlib commit fc9aeb6f7.