Opened 5 weeks ago

Closed 4 weeks ago

#23568 closed defect (fixed)

[PATCH] fix format issues in zstd code on 32 bit

Reported by: andreasstieger Owned by:
Priority: Medium Milestone: Tor: 0.3.1.x-final
Component: Core Tor/Tor Version: Tor: 0.3.1.7
Severity: Normal Keywords: zstd
Cc: ahf Actual Points:
Parent ID: Points:
Reviewer: ahf Sponsor:

Description (last modified by nickm)

Warnings/errors when building 0.3.1.7 on 32 bit, introduced in 380736d (tor-0.3.1.1-alpha)

[  103s] src/common/compress_zstd.c: In function 'tor_zstd_get_version_str':
[  103s] src/common/compress_zstd.c:65:19: error: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'size_t {aka unsigned int}' [-Werror=format=]
[  103s]                 "%lu.%lu.%lu",
[  103s]                  ~~^
[  103s]                  %u
[  103s]                 version_number / 10000 % 100,
[  103s]                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[  103s] src/common/compress_zstd.c:65:23: error: format '%lu' expects argument of type 'long unsigned int', but argument 5 has type 'size_t {aka unsigned int}' [-Werror=format=]
[  103s]                 "%lu.%lu.%lu",
[  103s]                      ~~^
[  103s]                      %u
[  103s] src/common/compress_zstd.c:67:16:
[  103s]                 version_number / 100 % 100,
[  103s]                 ~~~~~~~~~~~~~~~~~~~~~~~~~~
[  103s] src/common/compress_zstd.c:65:27: error: format '%lu' expects argument of type 'long unsigned int', but argument 6 has type 'size_t {aka unsigned int}' [-Werror=format=]
[  103s]                 "%lu.%lu.%lu",
[  103s]                          ~~^
[  103s]                          %u
[  103s] src/common/compress_zstd.c:68:16:
[  103s]                 version_number % 100);
[  103s]                 ~~~~~~~~~~~~~~~~~~~~`

%zu should be used here.

Tested on i586, x86_64, ppc, ppc64, aarch64, armv7. All on GNU gcc 7.2.1 on openSUSE.

Child Tickets

Attachments (1)

0001-in-zstd-compression-fix-32-bit-build.patch (1.1 KB) - added by andreasstieger 5 weeks ago.
v2 patch with %d / int cast

Download all attachments as: .zip

Change History (6)

comment:1 Changed 5 weeks ago by nickm

Description: modified (diff)
Milestone: Tor: 0.3.1.x-final
Status: newneeds_review

comment:2 Changed 5 weeks ago by ahf

Reviewer: ahf

comment:3 Changed 5 weeks ago by ahf

Status: needs_reviewneeds_revision

Hello!

Thanks for the patch! Since %zu isn't portable across all the platforms we support I'd suggest that we change the format string to use %d instead and cast the parameters to int.

Changed 5 weeks ago by andreasstieger

v2 patch with %d / int cast

comment:4 Changed 5 weeks ago by andreasstieger

Status: needs_revisionneeds_review

comment:5 Changed 4 weeks ago by nickm

Resolution: fixed
Status: needs_reviewclosed

ahf says it looks okay now; merging. Thanks!

Note: See TracTickets for help on using tickets.