Skip to content

fix(scanner): address -Wswitch-outside-range warnings when char is unsigned#42

Open
jamessan wants to merge 1 commit intotree-sitter-grammars:masterfrom
jamessan:scan-status
Open

fix(scanner): address -Wswitch-outside-range warnings when char is unsigned#42
jamessan wants to merge 1 commit intotree-sitter-grammars:masterfrom
jamessan:scan-status

Conversation

@jamessan
Copy link

C doesn't define the sign of the char type, so some architectures
(x86) use signed char where as others use unsigned char.

On architectures where unsigned char is used or if compiled with
"-funsigned-char", we see the below warnings:

src/scanner.c: In function ‘scn_dir_tag_pfx’:
src/scanner.c:470:13: warning: case label value is less than minimum value for type [-Wswitch-outside-range]
  470 |             case SCN_FAIL:
      |             ^~~~
src/scanner.c: In function ‘scn_tag’:
src/scanner.c:512:17: warning: case label value is less than minimum value for type [-Wswitch-outside-range]
  512 |                 case SCN_FAIL:
      |                 ^~~~
src/scanner.c:526:17: warning: case label value is less than minimum value for type [-Wswitch-outside-range]
  526 |                 case SCN_FAIL:
      |                 ^~~~

Define a new ScanStatus enum to use instead of independent #defines,
and update all the functions which previously returned char to instead
return ScanStatus.

…signed

C doesn't define the sign of the `char` type, so some architectures
(x86) use `signed char` where as others use `unsigned char`.

On architectures where unsigned char is used or if compiled with
"-funsigned-char", we see the below warnings:

    src/scanner.c: In function ‘scn_dir_tag_pfx’:
    src/scanner.c:470:13: warning: case label value is less than minimum value for type [-Wswitch-outside-range]
      470 |             case SCN_FAIL:
          |             ^~~~
    src/scanner.c: In function ‘scn_tag’:
    src/scanner.c:512:17: warning: case label value is less than minimum value for type [-Wswitch-outside-range]
      512 |                 case SCN_FAIL:
          |                 ^~~~
    src/scanner.c:526:17: warning: case label value is less than minimum value for type [-Wswitch-outside-range]
      526 |                 case SCN_FAIL:
          |                 ^~~~

Define a new `ScanStatus` enum to use instead of independent `#define`s,
and update all the functions which previously returned `char` to instead
return `ScanStatus`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant