tpm2-software / tpm2-totp

Attest the trustworthiness of a device against a human using time-based one-time passwords
https://tpm2-software.github.io
BSD 3-Clause "New" or "Revised" License
163 stars 36 forks source link

src: fix format string warnings when building for 32bit architectures #14

Closed jacmet closed 5 years ago

jacmet commented 5 years ago

Building currently gives the following warnings (which fails the build because of Werror) about format string mismatches:

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=] printf("%s%06ld", timestr, totp);


                   %06lld

src/libtpm2-totp.c: In function ‘tpm2totp_generateKey’:
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=]
         dbg("Calling Esys_GetRandom for %li bytes", SECRETLEN - *secret_size);
                                         ~~^
                                         %i

Fix it by using PRIu64 from inttypes.h for uint64_t and %zu for size_t.

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
codecov[bot] commented 5 years ago

Codecov Report

Merging #14 into master will not change coverage. The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #14   +/-   ##
=======================================
  Coverage   84.34%   84.34%           
=======================================
  Files           3        3           
  Lines         658      658           
=======================================
  Hits          555      555           
  Misses        103      103
Impacted Files Coverage Δ
src/tpm2-totp.c 82.65% <100%> (ø) :arrow_up:
src/libtpm2-totp.c 84.66% <100%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update ed86a39...f659971. Read the comment docs.

AndreasFuchsTPM commented 5 years ago

@jacmet Would you want this cherry-picked ot a bugfix 0.1.2 release ?

jacmet commented 5 years ago

@AndreasFuchsSIT that would be great! I'm currently packaging tpm2-totp in Buildroot (using v0.1.1), so it would be good to not have to carry the patch locally

AndreasFuchsTPM commented 5 years ago

@jacmet Done. P.S. Do you have a link ?

jacmet commented 5 years ago

I didn't post the series yet, I'll send you a link once ready

jacmet commented 5 years ago

Buildroot patches: https://patchwork.ozlabs.org/project/buildroot/list/?series=101467