Bug 1336515 - cli: compiler warning format string
Summary: cli: compiler warning format string
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: GlusterFS
Classification: Community
Component: cli
Version: mainline
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Muthu Vigneshwaran
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-05-16 17:05 UTC by Kaleb KEITHLEY
Modified: 2018-10-08 08:45 UTC (History)
5 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2018-10-08 08:45:59 UTC
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Embargoed:


Attachments (Terms of Use)

Description Kaleb KEITHLEY 2016-05-16 17:05:32 UTC
Description of problem:


Making all in firewalld
Making all in cli
Making all in src
  CC       cli.o
  CC       registry.o
  CC       input.o
  CC       cli-cmd.o
  CC       cli-rl.o
  CC       cli-cmd-global.o
  CC       cli-cmd-volume.o
  CC       cli-cmd-peer.o
  CC       cli-rpc-ops.o
  CC       cli-cmd-parser.o
  CC       cli-cmd-system.o
cli-rpc-ops.c: In function 'cli_populate_req_dict_for_delete':
cli-rpc-ops.c:9815:55: warning: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'size_t {aka unsigned int}' [-Wformat=]
         ret = snprintf (key, sizeof (key), "snapname%lu", index);
                                                       ^
  CC       cli-cmd-misc.o
  CC       cli-xml-output.o
  CC       cli-quotad-client.o
  CC       cli-cmd-snapshot.o
  CCLD     gluster



Version-Release number of selected component (if applicable):


How reproducible:


Steps to Reproduce:
1.
2.
3.

Actual results:


Expected results:


Additional info:

Comment 1 Muthu Vigneshwaran 2016-07-15 09:15:38 UTC
Hi,

In the function, size_t index is used, which can hold any array index. Depending on the implementation it can be unsigned char/short/int/long/long long.

I tried the same on Fedora, and the default compiler type is:

echo | gcc -E -xc -include 'stddef.h' - | grep size_t

Output is:
typedef long unsigned int size_t

So, the correct format specifier being %lu is used and it does not throw any warning.

I think we should close the bug as this is more compiler dependent.

Comment 2 Kaleb KEITHLEY 2016-07-15 12:53:18 UTC
Did you try compiling on 32-bit Fedora?

%zu is the correct format string for variables of type size_t. Please see the man page for printf(3)

Comment 3 Atin Mukherjee 2018-10-07 13:15:11 UTC
Xavi - does https://review.gluster.org/#/c/21276/ address it? Could you check?

Comment 4 Xavi Hernandez 2018-10-08 08:45:59 UTC
This problem was already addressed as part of bug #1198849. The patch that already solves this is: https://review.gluster.org/14933

So I'm closing this bug as CURRENTRELEASE.


Note You need to log in before you can comment on or make changes to this bug.