scarybeasts / beebjit

A very fast BBC Micro emulator.
Other
132 stars 15 forks source link

Fix uses of PRIu8 which should be SCNu8 #46

Closed ojwb closed 1 year ago

ojwb commented 1 year ago

Fixes two warnings with GCC 12.

ojwb commented 1 year ago

Warnings fixed are:

main.c: In function ‘beebjit_main’:
main.c:187:29: error: format ‘%u’ expects argument of type ‘unsigned int *’, but argument 3 has type ‘uint8_t *’ {aka ‘unsigned char *’} [-Werror=format=]
  187 |         (void) sscanf(val1, "%"PRIu8, &from);
      |                             ^~~       ~~~~~
      |                                       |
      |                                       uint8_t * {aka unsigned char *}
In file included from main.c:27:
/usr/include/inttypes.h:102:26: note: format string is defined here
  102 | # define PRIu8          "u"
main.c:188:29: error: format ‘%u’ expects argument of type ‘unsigned int *’, but argument 3 has type ‘uint8_t *’ {aka ‘unsigned char *’} [-Werror=format=]
  188 |         (void) sscanf(val2, "%"PRIu8, &to);
      |                             ^~~       ~~~
      |                                       |
      |                                       uint8_t * {aka unsigned char *}
/usr/include/inttypes.h:102:26: note: format string is defined here
  102 | # define PRIu8          "u"
scarybeasts commented 1 year ago

Thanks and sorry about that. I was working on macOS which did not seem to care. I fixed it a little differently here because the Window cross compile environment does not have SCNu8 defined (due to some other define I had to set, which I need to look into again one day). https://github.com/scarybeasts/beebjit/commit/162e3fb0b72bfd112fa580da5662f9b8bf5f453c

ojwb commented 1 year ago

PRIu32 in sscanf is technically wrong too and should be SCNu32 - looking at the headers in the mingw cross-compiler I have installed it looks like it's only SCN...8 that are missing.

I suspect if you stick to 32 and wider you'll probably get away with this in practice. I think the underlying point here is that some types passed through varargs get promoted, but in scanf a pointer is passed so that type promotion doesn't happen. In practice a 32 bit unsigned integer type is going to map to unsigned int or unsigned long so won't get promoted.

scarybeasts commented 1 year ago

I'll probably replace all these sscanf() with something more palatable.