Fix some format string warnings from clang
authorAntonio Ospite <ao2@ao2.it>
Sat, 7 Nov 2015 21:33:03 +0000 (22:33 +0100)
committerAntonio Ospite <ao2@ao2.it>
Sat, 7 Nov 2015 21:46:08 +0000 (22:46 +0100)
Building with clang gives some format string warnings as below, fix them
by using the correct format string when printing out the values.

  .../libam7xxx/src/am7xxx.c:804:38: warning:
  format specifies type 'unsigned char' but the argument has type 'int'
  [-Wformat]
                        (*dev)->desc->configuration, current_configuration);
                                                     ^~~~~~~~~~~~~~~~~~~~~
  .../libam7xxx/src/am7xxx.c:65:85: note:
  expanded from macro 'debug'
  #define debug(ctx, ...)   log_message(ctx, AM7XXX_LOG_DEBUG, __func__, 0, __VA_ARGS__)
                                                                            ^
  1 warning generated.

  [...]

  .../libam7xxx/examples/am7xxx-modeswitch.c:75:5:
  warning: format specifies type 'unsigned char' but the argument has type
  'int' [-Wformat]
                                  AM7XXX_STORAGE_CONFIGURATION);
                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
  .../libam7xxx/examples/am7xxx-modeswitch.c:26:38:
  note: expanded from macro 'AM7XXX_STORAGE_CONFIGURATION'
  #define AM7XXX_STORAGE_CONFIGURATION 1
                                       ^
  .../libam7xxx/examples/am7xxx-modeswitch.c:87:4:
  warning: format specifies type 'unsigned char' but the argument has type
  'int' [-Wformat]
                          AM7XXX_STORAGE_INTERFACE);
                          ^~~~~~~~~~~~~~~~~~~~~~~~
  .../libam7xxx/examples/am7xxx-modeswitch.c:27:38:
  note: expanded from macro 'AM7XXX_STORAGE_INTERFACE'
  #define AM7XXX_STORAGE_INTERFACE     0
                                       ^
  .../libam7xxx/examples/am7xxx-modeswitch.c:104:4:
  warning: format specifies type 'unsigned char' but the argument has type
  'int' [-Wformat]
                          AM7XXX_STORAGE_CONFIGURATION, current_configuration);
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
  .../libam7xxx/examples/am7xxx-modeswitch.c:26:38:
  note: expanded from macro 'AM7XXX_STORAGE_CONFIGURATION'
  #define AM7XXX_STORAGE_CONFIGURATION 1
                                       ^
  .../libam7xxx/examples/am7xxx-modeswitch.c:104:34:
  warning: format specifies type 'unsigned char' but the argument has type
  'int' [-Wformat]
                          AM7XXX_STORAGE_CONFIGURATION, current_configuration);
                                                        ^~~~~~~~~~~~~~~~~~~~~
  4 warnings generated.

examples/am7xxx-modeswitch.c
src/am7xxx.c

index 62db796..793130e 100644 (file)
@@ -71,7 +71,7 @@ int main(void)
                if (ret < 0) {
                        fprintf(stderr, "libusb_set_configuration failed: %s\n",
                                libusb_error_name(ret));
                if (ret < 0) {
                        fprintf(stderr, "libusb_set_configuration failed: %s\n",
                                libusb_error_name(ret));
-                       fprintf(stderr, "Cannot set configuration %hhu\n",
+                       fprintf(stderr, "Cannot set configuration %d\n",
                                AM7XXX_STORAGE_CONFIGURATION);
                        goto out_libusb_close;
                }
                                AM7XXX_STORAGE_CONFIGURATION);
                        goto out_libusb_close;
                }
@@ -83,7 +83,7 @@ int main(void)
        if (ret < 0) {
                fprintf(stderr, "libusb_claim_interface failed: %s\n",
                        libusb_error_name(ret));
        if (ret < 0) {
                fprintf(stderr, "libusb_claim_interface failed: %s\n",
                        libusb_error_name(ret));
-               fprintf(stderr, "Cannot claim interface %hhu\n",
+               fprintf(stderr, "Cannot claim interface %d\n",
                        AM7XXX_STORAGE_INTERFACE);
                goto out_libusb_close;
        }
                        AM7XXX_STORAGE_INTERFACE);
                goto out_libusb_close;
        }
@@ -100,7 +100,7 @@ int main(void)
        }
 
        if (current_configuration != AM7XXX_STORAGE_CONFIGURATION) {
        }
 
        if (current_configuration != AM7XXX_STORAGE_CONFIGURATION) {
-               fprintf(stderr, "libusb configuration changed (expected: %hhu, current: %hhu\n",
+               fprintf(stderr, "libusb configuration changed (expected: %d, current: %d\n",
                        AM7XXX_STORAGE_CONFIGURATION, current_configuration);
                ret = -EINVAL;
                goto out_libusb_release_interface;
                        AM7XXX_STORAGE_CONFIGURATION, current_configuration);
                ret = -EINVAL;
                goto out_libusb_release_interface;
index b988267..76df87d 100644 (file)
@@ -800,7 +800,7 @@ static int open_device(am7xxx_context *ctx,
        }
 
        if (current_configuration != (*dev)->desc->configuration) {
        }
 
        if (current_configuration != (*dev)->desc->configuration) {
-               debug(ctx, "libusb configuration changed (expected: %hhu, current: %hhu\n",
+               debug(ctx, "libusb configuration changed (expected: %hhu, current: %d\n",
                      (*dev)->desc->configuration, current_configuration);
                ret = -EINVAL;
                goto out_libusb_release_interface;
                      (*dev)->desc->configuration, current_configuration);
                ret = -EINVAL;
                goto out_libusb_release_interface;