maindmidecode - Support: sr #110421, Format warnings when building with...

 
 

sr #110421: Format warnings when building with GCC

Submitter:  - <_231410>
Submitted:  Sun 10 Jan 2021 09:14:57 PM UTC
   
 
Category:  None Priority:  5 - Normal
Severity:  2 - Minor Status:  Done
Privacy:  Public Assigned to:  khali
Open/Closed:  Closed Operating System:  GNU/Linux
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Tue 19 Jan 2021 03:24:33 PM UTC, comment #11: 
Jean Delvare <khali>
Group administrator
Wed 13 Jan 2021 10:48:03 AM UTC, comment #10: 

Tested build with patch. Now it builds without warnings. Thanks.

- <_231410>
Tue 12 Jan 2021 12:09:57 PM UTC, comment #9: 

Gcc 10 with -Wall -Wextra -pedantic did not help, but clang did, thanks.

I have posted a patch which fixes the warnings you reported, however it introduces other warnings for some compilers, which reminded me why I did things the strange way they were.

These sprintf calls are writing to static buffers which are sized for exactly the string which is being generated. I know that the number is small and will not need more than 3 characters to print, however the compiler sees an int so it thinks it could require more than 3 characters to print, and complains that the buffer is too small.

One way to fix it is to provide larger buffers, which is wasting stack space, and depends on the architecture's width.

The other way, I suppose, would be to explicitly cast the parameter to a smaller type. I'll try that.

Jean Delvare <khali>
Group administrator
Tue 12 Jan 2021 11:44:10 AM UTC, comment #8: 

$ clang -v
clang version 11.0.0 (Fedora 11.0.0-2.fc33)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/10
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/10
Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/10

- <_231410>
Tue 12 Jan 2021 11:43:35 AM UTC, comment #7: 

Can be easily reproduced with Clang compiler:

export CC=clang
export CFLAGS="-O2 -Wall -Wextra -Wformat"

- <_231410>
Tue 12 Jan 2021 11:02:09 AM UTC, comment #6: 

Please try -Wall -Wextra -pedantic then, but on GCC 10.

- <_231410>
Tue 12 Jan 2021 10:55:08 AM UTC, comment #5: 

Still can't reproduce. Might have to do with the redhat-specific -specs parameters. Anyway, I'll try to fix theses warnings and you get to test the patch.

Jean Delvare <khali>
Group administrator
Tue 12 Jan 2021 10:45:48 AM UTC, comment #4: 

You only need -Wall, which includes -Wformat.

On Fedora we use the following default build flags:

-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection

- <_231410>
Tue 12 Jan 2021 08:34:38 AM UTC, comment #3: 

What's your exact build command line? I tried various versions of gcc on x86_64, including 10.2.1, with -m32, and I still can't see these warnings.

Jean Delvare <khali>
Group administrator
Mon 11 Jan 2021 04:07:46 PM UTC, comment #2: 

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/10/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.2.1 20201125 (Red Hat 10.2.1-9) (GCC)

- <_231410>
Mon 11 Jan 2021 01:14:47 PM UTC, comment #1: 

Which version of gcc, on which architecture? I can't see any of these warnings with gcc 7.5.0 on x86_64.

Jean Delvare <khali>
Group administrator
Sun 10 Jan 2021 09:14:57 PM UTC, original submission:  

Hello. There are some format warnings when building the project with GCC with -Wall compiler flag:

[32/48] Building C object src/dmidecode/CMakeFiles/dmidecode.dir/dmioem.c.o

../src/dmidecode/dmioem.c:149:27: warning: format specifies type 'unsigned short' but the argument has type 'u8' (aka 'unsigned char') [-Wformat]

        sprintf(attr, "NIC %hu", id);

                           ~~~   ^~

                           %hhu

1 warning generated.

[40/48] Building C object src/dmidecod...CMakeFiles/dmidecode.dir/dmidecode.c.o

../src/dmidecode/dmidecode.c:2210:36: warning: format specifies type 'unsigned short' but the argument has type 'int' [-Wformat]

                sprintf(attr, "Peer Device %hu", i);

                                           ~~~   ^

                                           %d

../src/dmidecode/dmidecode.c:2276:31: warning: format specifies type 'unsigned short' but the argument has type 'int' [-Wformat]

                sprintf(attr, "String %hu", i);

                                      ~~~   ^

                                      %d

../src/dmidecode/dmidecode.c:2294:31: warning: format specifies type 'unsigned short' but the argument has type 'int' [-Wformat]

                sprintf(attr, "Option %hu", i);

                                      ~~~   ^

                                      %d

../src/dmidecode/dmidecode.c:2478:36: warning: format specifies type 'unsigned short' but the argument has type 'int' [-Wformat]

                        sprintf(attr, "Descriptor %hu", i + 1);

                                                  ~~~   ^~~~~

                                                  %d

../src/dmidecode/dmidecode.c:2481:37: warning: format specifies type 'unsigned short' but the argument has type 'int' [-Wformat]

                        sprintf(attr, "Data Format %hu", i + 1);

                                                   ~~~   ^~~~~

                                                   %d

../src/dmidecode/dmidecode.c:3498:36: warning: format specifies type 'unsigned short' but the argument has type 'int' [-Wformat]

                sprintf(attr, "Device %hu Load", i);

                                      ~~~        ^

                                      %d

../src/dmidecode/dmidecode.c:3502:39: warning: format specifies type 'unsigned short' but the argument has type 'int' [-Wformat]

                        sprintf(attr, "Device %hu Handle", i);

                                              ~~~          ^

                                              %d

7 warnings generated.

- <_231410>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #50708:  dmidecode-fix-format-warnings.patch added by khali (2KiB - text/x-patch - [PATCH v2] dmidecode: Fix format warnings)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by khali (Posted a comment)
  • -email is unavailable- added by _231410 (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 12 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-01-19 khali StatusNeed Info Done
        Open/ClosedOpen Closed
    2021-01-13 khali StatusIn Progress Need Info
    2021-01-12 khali Attached File#50706 Removed
    2021-01-12 khali Attached File- Added dmidecode-fix-format-warnings.patch, #50708
    2021-01-12 khali StatusNeed Info In Progress
    2021-01-12 khali Attached File- Added dmidecode-fix-format-warnings.patch, #50706
        Severity3 - Normal 2 - Minor
        StatusWorks For Me Need Info
    2021-01-12 khali StatusNeed Info Works For Me
    2021-01-11 khali StatusNone Need Info
        Assigned toNone khali

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code