public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/58959] New: Add warning when format specifiers refers to wrong signess
@ 2013-11-01 10:05 lotharlutz at gmx dot de
  2013-11-01 10:08 ` [Bug c/58959] " lotharlutz at gmx dot de
  2014-03-25 22:22 ` mpolacek at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: lotharlutz at gmx dot de @ 2013-11-01 10:05 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="UTF-8", Size: 3253 bytes --]

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58959

            Bug ID: 58959
           Summary: Add warning when format specifiers refers to wrong
                    signess
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lotharlutz at gmx dot de

When using a format specifier that refers to a different sign (signed vs
unsigned) as to corresponding variable has, a warning should be emitted.

Version:
gcc version 4.8.2 20131017 (Red Hat 4.8.2-1) (GCC)

Example:
-----
#include <stdio.h>

int main()
{
    short i = -1;

    //correct usage
    printf("%hd\n",i);

    //should yield a warning, but does not
    printf("%hu\n",i);

    //correctly yields a warning
    printf("%ld\n",i);

return 0;
}
----
gcc -Wall -Wextra test.c
test.c: In function ‘main’:
test.c:14:5: warning: format ‘%ld’ expects argument of type ‘long int’, but
argument 2 has type ‘int’ [-Wformat=]
     printf("%ld\n",i);

gcc warns when the variable has the wrong size (line 14), but not on the wrong
size (line 11)
>From gcc-bugs-return-433245-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Fri Nov 01 10:07:25 2013
Return-Path: <gcc-bugs-return-433245-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 1277 invoked by alias); 1 Nov 2013 10:07:25 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 1247 invoked by uid 48); 1 Nov 2013 10:07:22 -0000
From: "lotharlutz at gmx dot de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/58959] Add warning when format specifiers refers to wrong signess
Date: Fri, 01 Nov 2013 10:07:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c
X-Bugzilla-Version: 4.8.2
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: lotharlutz at gmx dot de
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: attachments.created
Message-ID: <bug-58959-4-mtepB7J9Ma@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-58959-4@http.gcc.gnu.org/bugzilla/>
References: <bug-58959-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2013-11/txt/msg00022.txt.bz2
Content-length: 234

http://gcc.gnu.org/bugzilla/show_bug.cgi?idX959

--- Comment #1 from Markus Mayer <lotharlutz at gmx dot de> ---
Created attachment 31131
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id1131&actioníit
preprocessed test file


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/58959] Add warning when format specifiers refers to wrong signess
  2013-11-01 10:05 [Bug c/58959] New: Add warning when format specifiers refers to wrong signess lotharlutz at gmx dot de
@ 2013-11-01 10:08 ` lotharlutz at gmx dot de
  2014-03-25 22:22 ` mpolacek at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: lotharlutz at gmx dot de @ 2013-11-01 10:08 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58959

--- Comment #2 from Markus Mayer <lotharlutz at gmx dot de> ---
Created attachment 31132
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31132&action=edit
output of 'gcc -v -save-temps -Wall -Wextra test.c'


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/58959] Add warning when format specifiers refers to wrong signess
  2013-11-01 10:05 [Bug c/58959] New: Add warning when format specifiers refers to wrong signess lotharlutz at gmx dot de
  2013-11-01 10:08 ` [Bug c/58959] " lotharlutz at gmx dot de
@ 2014-03-25 22:22 ` mpolacek at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2014-03-25 22:22 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58959

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |mpolacek at gcc dot gnu.org
         Resolution|---                         |INVALID

--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
This is expected.  Shorts and chars are passed as ints due to default
promotions.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-03-25 22:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-01 10:05 [Bug c/58959] New: Add warning when format specifiers refers to wrong signess lotharlutz at gmx dot de
2013-11-01 10:08 ` [Bug c/58959] " lotharlutz at gmx dot de
2014-03-25 22:22 ` mpolacek at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).