Community
cancel
Showing results for 
Search instead for 
Did you mean: 
dpeterc
Beginner
309 Views

Why does -Wall not include -Wformat ?

Jump to solution

By compiling all my programs with -Wall option, I was under impression I would get all relevant warnings, which compiler can provide.

But apparently, format errors on string manipulation (quite a big error with potential small, hard to discover memory overwrites) is not reported, even if compiler has diagnostics to do it.

#include <stdio.h>
#include <stdlib.h>
int main()
{
 static unsigned char a=1, b=2, c=3;
 char *numStr="123";
 
 sscanf(numStr, "%d", &b);

 printf("%d %d %d\n", a, b, c);
 return(0);
}

By compiling it with this command I don't get any warning.

icc -Wall bug.c

but if I compile it with gcc

gcc -Wall bug.c

I get proper warning:

bug.c: In function 'main':
bug.c:8:19: warning: format '%d' expects argument of type 'int *', but argument 3 has type 'unsigned char *' [-Wformat=]
  sscanf(numStr, "%d", &b);
                  ~^   ~~

which also tells me which compiler option triggered the warning (-Wformat)

So I try it with icc, and I get

icc -Wformat bug.c

bug.c(8): warning #181: argument of type "unsigned char *" is incompatible with format "%d", expecting argument of type "int *"
   sscanf(numStr, "%d", &b);

So why is -Wformat not included in -Wall ?

 

My operating system is Linux, OpenSUSE 15, 64 bits.

And this is the version of my compiler:

icc (ICC) 19.1.0.166 20191121
Copyright (C) 1985-2019 Intel Corporation.  All rights reserved.

 

 

0 Kudos
1 Solution
Viet_H_Intel
Moderator
309 Views

AFAIK, we don't have such a list. And I've submitted this bug to our Developer for a fix.

View solution in original post

6 Replies
RahulV_intel
Moderator
309 Views

Hi,

Thanks for reporting this issue. Ideally, "-Wall" must include "-Wformat" warnings as well. We will take this issue to the concerned team.

 

--Rahul

Viet_H_Intel
Moderator
309 Views

ICC's diagnosis may behave different than GCC's. You can add -ww181 to turn on this warning.

dpeterc
Beginner
309 Views

Viet Hoang (Intel) wrote:

ICC's diagnosis may behave different than GCC's. You can add -ww181 to turn on this warning.

I understand that gcc and icc are different, and I know how to enable -Wformat in icc.
My question is why icc does not include -Wformat among -Wall, since that warning is both serious and quite basic.

Or if someone can point me to the list of warnings that are included in -Wall, so I will know which others do I need to include manually.

Viet_H_Intel
Moderator
310 Views

AFAIK, we don't have such a list. And I've submitted this bug to our Developer for a fix.

View solution in original post

dpeterc
Beginner
309 Views

Thank you very much!

Viet_H_Intel
Moderator
8 Views

Unfortunately, we wont fix this issue. Please use -ww181 to turn on this warning.

I am going to close this case.


Thanks,


Reply