0001-src-fix-format-string-warnings-when-building-for-32b.patch 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. From 1d39994398a886584c5fb14b3a646c4ae6b0d35c Mon Sep 17 00:00:00 2001
  2. From: Peter Korsgaard <peter@korsgaard.com>
  3. Date: Mon, 8 Apr 2019 11:03:09 +0200
  4. Subject: [PATCH] src: fix format string warnings when building for 32bit
  5. architectures
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. Building currently gives the following warnings (which fails the build
  10. because of Werror) about format string mismatches:
  11. src/tpm2-totp.c:343:23: error: format ‘%ld’ expects argument of type ‘long int’, but argument 3 has type ‘uint64_t’ {aka ‘long long unsigned int’} [-Werror=format=]
  12. printf("%s%06ld", timestr, totp);
  13. ~~~~^ ~~~~
  14. %06lld
  15. src/libtpm2-totp.c: In function ‘tpm2totp_generateKey’:
  16. src/libtpm2-totp.c:172:13: error: format ‘%li’ expects argument of type ‘long int’, but argument 3 has type ‘size_t’ {aka ‘unsigned int’} [-Werror=format=]
  17. dbg("Calling Esys_GetRandom for %li bytes", SECRETLEN - *secret_size);
  18. ~~^
  19. %i
  20. Fix it by using PRIu64 from inttypes.h for uint64_t and %zu for size_t.
  21. Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
  22. ---
  23. src/libtpm2-totp.c | 2 +-
  24. src/tpm2-totp.c | 2 +-
  25. 2 files changed, 2 insertions(+), 2 deletions(-)
  26. diff --git a/src/libtpm2-totp.c b/src/libtpm2-totp.c
  27. index e740ab1..6942771 100644
  28. --- a/src/libtpm2-totp.c
  29. +++ b/src/libtpm2-totp.c
  30. @@ -169,7 +169,7 @@ tpm2totp_generateKey(uint32_t pcrs, uint32_t banks, const char *password,
  31. if (rc != TPM2_RC_INITIALIZE) chkrc(rc, goto error);
  32. while (*secret_size < SECRETLEN) {
  33. - dbg("Calling Esys_GetRandom for %li bytes", SECRETLEN - *secret_size);
  34. + dbg("Calling Esys_GetRandom for %zu bytes", SECRETLEN - *secret_size);
  35. rc = Esys_GetRandom(ctx,
  36. ESYS_TR_NONE, ESYS_TR_NONE, ESYS_TR_NONE,
  37. SECRETLEN - *secret_size, &t);
  38. diff --git a/src/tpm2-totp.c b/src/tpm2-totp.c
  39. index 47b661a..d5dcdce 100644
  40. --- a/src/tpm2-totp.c
  41. +++ b/src/tpm2-totp.c
  42. @@ -340,7 +340,7 @@ main(int argc, char **argv)
  43. localtime (&now));
  44. chkrc(rc, exit(1));
  45. }
  46. - printf("%s%06ld", timestr, totp);
  47. + printf("%s%06" PRIu64, timestr, totp);
  48. break;
  49. case CMD_RESEAL:
  50. rc = tpm2totp_loadKey_nv(opt.nvindex, &keyBlob, &keyBlob_size);
  51. --
  52. 2.11.0