public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/44984]  New: gcc passes unsigned instead of int for printf width/precision (warnings generated)
@ 2010-07-19  7:25 jay dot krell at cornell dot edu
  2010-07-20 22:51 ` [Bug middle-end/44984] " pinskia at gcc dot gnu dot org
  2010-07-20 22:53 ` pinskia at gcc dot gnu dot org
  0 siblings, 2 replies; 5+ messages in thread
From: jay dot krell at cornell dot edu @ 2010-07-19  7:25 UTC (permalink / raw)
  To: gcc-bugs

4.3.5 but 4.5.0 looks about the same, but it has an additional instance:


mber/dpd -I../libdecnumber -I/usr/local/include   ../../gcc/gcc/opts.c -o
opts.o
../../gcc/gcc/opts.c: In function `wrap_help':
../../gcc/gcc/opts.c:1037: warning: field width is not type int (arg 3)
../../gcc/gcc/opts.c:1037: warning: field width is not type int (arg 5)
../../gcc/gcc/opts.c: In function `common_handle_option':
../../gcc/gcc/opts.c:1409: warning: field width is not type int (arg 3)
gcc -c   -g -O2 -DIN_GCC   -W -Wall -Wwrite-strings -Wstrict-prototypes
-Wmissin


jbook2:gcc jay$ diff -uw opts.c.orig opts.c
--- opts.c.orig    2010-07-19 00:07:18.000000000 -0700
+++ opts.c    2010-07-19 00:16:27.000000000 -0700
@@ -1034,7 +1034,10 @@
         }
     }

-      printf( "  %-*.*s %.*s\n", col_width, item_width, item, len, help);
+      gcc_assert(col_width <= INT_MAX);
+      gcc_assert(item_width <= INT_MAX);
+      gcc_assert(len <= INT_MAX);
+      printf ("  %-*.*s %.*s\n", (int)col_width, (int)item_width, item,
(int)len, help);
       item_width = 0;
       while (help[len] == ' ')
     len++;
@@ -1404,9 +1407,12 @@
             }

         if (i == cl_lang_count)
+          {
+            gcc_assert (len <= INT_MAX);
           fnotice (stderr,
                "warning: unrecognized argument to --help= switch: %.*s\n",
-               len, a);
+                 (int)len, a);
+          }
           }

         if (comma == NULL)


This makes a line go a little over 80 columns, but one of the "nearby" lines
does already.
 (nearby as presented here, not really in the code)

This probably isn't the best fix.
  if the output is "not important", and someone manages to create huge data,
should still work.
  Yes, I'm aware of that "huge" is 2GB.

Maybe:

int to_reasonable_diagnostic_length(unsigned i)
{
  return (i <= INT_MAX) ? i : 255;
}

or

int unint_to_int_pin(unsigned i)
{
  return (i <= INT_MAX) ? i : INT_MAX;
}

and then apply those.

 - Jay


-- 
           Summary: gcc passes unsigned instead of int for printf
                    width/precision (warnings generated)
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jay dot krell at cornell dot edu


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


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

* [Bug middle-end/44984] gcc passes unsigned instead of int for printf width/precision (warnings generated)
  2010-07-19  7:25 [Bug middle-end/44984] New: gcc passes unsigned instead of int for printf width/precision (warnings generated) jay dot krell at cornell dot edu
@ 2010-07-20 22:51 ` pinskia at gcc dot gnu dot org
  2010-07-20 22:53 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-07-20 22:51 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2010-07-20 22:50 -------
unsigned int and int are passed exactly the same for varargs and in fact the C
standard says getting an unsigned version of the signed type for varargs is
valid.


-- 


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


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

* [Bug middle-end/44984] gcc passes unsigned instead of int for printf width/precision (warnings generated)
  2010-07-19  7:25 [Bug middle-end/44984] New: gcc passes unsigned instead of int for printf width/precision (warnings generated) jay dot krell at cornell dot edu
  2010-07-20 22:51 ` [Bug middle-end/44984] " pinskia at gcc dot gnu dot org
@ 2010-07-20 22:53 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-07-20 22:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2010-07-20 22:52 -------
What compiler version is giving a warning for this case?  That is can you
provide the output of "gcc -v" ?


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING


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


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

* [Bug middle-end/44984] gcc passes unsigned instead of int for printf width/precision (warnings generated)
       [not found] <bug-44984-4@http.gcc.gnu.org/bugzilla/>
  2010-10-02 10:28 ` jay.krell at cornell dot edu
@ 2013-11-10  8:17 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2013-11-10  8:17 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|---                         |INVALID

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
No feedback in 3 years so closing.


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

* [Bug middle-end/44984] gcc passes unsigned instead of int for printf width/precision (warnings generated)
       [not found] <bug-44984-4@http.gcc.gnu.org/bugzilla/>
@ 2010-10-02 10:28 ` jay.krell at cornell dot edu
  2013-11-10  8:17 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 5+ messages in thread
From: jay.krell at cornell dot edu @ 2010-10-02 10:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jay <jay.krell at cornell dot edu> 2010-10-02 10:27:53 UTC ---
> which compiler produces this


I'm afraid I'm not sure and can't quickly/easily make it happen again. Sorry.


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

end of thread, other threads:[~2013-11-10  8:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-19  7:25 [Bug middle-end/44984] New: gcc passes unsigned instead of int for printf width/precision (warnings generated) jay dot krell at cornell dot edu
2010-07-20 22:51 ` [Bug middle-end/44984] " pinskia at gcc dot gnu dot org
2010-07-20 22:53 ` pinskia at gcc dot gnu dot org
     [not found] <bug-44984-4@http.gcc.gnu.org/bugzilla/>
2010-10-02 10:28 ` jay.krell at cornell dot edu
2013-11-10  8:17 ` pinskia 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).