sb-grovel uses %d where it should be using %ld

Bug #1465748 reported by Faré
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Fix Released
Undecided
Unassigned

Bug Description

Example failure, while compiling CLON:

CL-USER> (sb-posix:setenv "CC" "cc" 1)
0
CL-USER> (asdf:make 'com.dvlsoft.clon :force t)
WARNING: PARSE-VERSION: "1.0b23" doesn't follow asdf version numbering
convention
WARNING: Invalid :version specifier "1.0b23" for component
"com.dvlsoft.clon" from file
#P"/home/tunes/cl/THIRDPARTY/clon/com.dvlsoft.clon.asd", using NIL
instead
WARNING: Invalid :version specifier "1.0b23" for component
"com.dvlsoft.clon" from file
#P"/home/tunes/cl/THIRDPARTY/clon/com.dvlsoft.clon.asd", using NIL
instead
WARNING: PARSE-VERSION: "1.0b23" doesn't follow asdf version numbering
convention
WARNING: Invalid :version specifier "1.0b23" for component
"com.dvlsoft.clon.core" from file
#P"/home/tunes/cl/THIRDPARTY/clon/com.dvlsoft.clon.core.asd", using
NIL instead
WARNING: Invalid :version specifier "1.0b23" for component
"com.dvlsoft.clon.core" from file
#P"/home/tunes/cl/THIRDPARTY/clon/com.dvlsoft.clon.core.asd", using
NIL instead
WARNING: PARSE-VERSION: "1.0b23" doesn't follow asdf version numbering
convention
WARNING: Invalid :version specifier "1.0b23" for component
"com.dvlsoft.clon.termio" from file
#P"/home/tunes/cl/THIRDPARTY/clon/com.dvlsoft.clon.termio.asd", using
NIL instead
WARNING: Invalid :version specifier "1.0b23" for component
"com.dvlsoft.clon.termio" from file
#P"/home/tunes/cl/THIRDPARTY/clon/com.dvlsoft.clon.termio.asd", using
NIL instead
(/home/tunes/cl/THIRDPARTY/clon/termio/sbcl/constants.lisp
 /home/tunes/.cache/common-lisp/sbcl-1.2.11.54-1ab7880-linux-x64/home/tunes/cl/THIRDPARTY/clon/termio/sbcl/constants.fasl
 /home/tunes/.cache/common-lisp/sbcl-1.2.11.54-1ab7880-linux-x64/home/tunes/cl/THIRDPARTY/clon/termio/sbcl/constants.fasl
 /home/tunes/.cache/common-lisp/sbcl-1.2.11.54-1ab7880-linux-x64/home/tunes/cl/THIRDPARTY/clon/termio/sbcl/foo.c
 /home/tunes/.cache/common-lisp/sbcl-1.2.11.54-1ab7880-linux-x64/home/tunes/cl/THIRDPARTY/clon/termio/sbcl/a.out
 /home/tunes/.cache/common-lisp/sbcl-1.2.11.54-1ab7880-linux-x64/home/tunes/cl/THIRDPARTY/clon/termio/sbcl/constants.lisp-temp)
/home/tunes/.cache/common-lisp/sbcl-1.2.11.54-1ab7880-linux-x64/home/tunes/cl/THIRDPARTY/clon/termio/sbcl/foo.c:
In function ‘main’:
/home/tunes/.cache/common-lisp/sbcl-1.2.11.54-1ab7880-linux-x64/home/tunes/cl/THIRDPARTY/clon/termio/sbcl/foo.c:19:5:
warning: format ‘%d’ expects argument of type ‘int’, but argument 3
has type ‘long unsigned int’ [-Wformat=]
     fprintf (out, " (cl:setf (cl:gethash %d *integer-sizes*)
'sb-alien:char)\n", sizeof(char));
     ^
/home/tunes/.cache/common-lisp/sbcl-1.2.11.54-1ab7880-linux-x64/home/tunes/cl/THIRDPARTY/clon/termio/sbcl/foo.c:20:5:
warning: format ‘%d’ expects argument of type ‘int’, but argument 3
has type ‘long unsigned int’ [-Wformat=]
     fprintf (out, " (cl:setf (cl:gethash %d *integer-sizes*)
'sb-alien:short)\n", sizeof(short));
     ^
/home/tunes/.cache/common-lisp/sbcl-1.2.11.54-1ab7880-linux-x64/home/tunes/cl/THIRDPARTY/clon/termio/sbcl/foo.c:21:5:
warning: format ‘%d’ expects argument of type ‘int’, but argument 3
has type ‘long unsigned int’ [-Wformat=]
     fprintf (out, " (cl:setf (cl:gethash %d *integer-sizes*)
'sb-alien:long)\n", sizeof(long));
     ^
/home/tunes/.cache/common-lisp/sbcl-1.2.11.54-1ab7880-linux-x64/home/tunes/cl/THIRDPARTY/clon/termio/sbcl/foo.c:22:5:
warning: format ‘%d’ expects argument of type ‘int’, but argument 3
has type ‘long unsigned int’ [-Wformat=]
     fprintf (out, " (cl:setf (cl:gethash %d *integer-sizes*)
'sb-alien:int)\n", sizeof(int));
     ^
/home/tunes/.cache/common-lisp/sbcl-1.2.11.54-1ab7880-linux-x64/home/tunes/cl/THIRDPARTY/clon/termio/sbcl/foo.c:29:135:
warning: format ‘%d’ expects argument of type ‘int’, but argument 3
has type ‘long unsigned int’ [-Wformat=]
     fprintf (out, "(cl:eval-when (:compile-toplevel :load-toplevel
:execute) (sb-grovel::define-c-struct WINSIZE %d\n", sizeof(struct
winsize));

                                                                ^
/home/tunes/.cache/common-lisp/sbcl-1.2.11.54-1ab7880-linux-x64/home/tunes/cl/THIRDPARTY/clon/termio/sbcl/foo.c:32:5:
warning: format ‘%d’ expects argument of type ‘int’, but argument 3
has type ‘long unsigned int’ [-Wformat=]
     fprintf (out, " %d\n", ((unsigned long)&(t.ws_row)) - ((unsigned
long)&(t)));
     ^
/home/tunes/.cache/common-lisp/sbcl-1.2.11.54-1ab7880-linux-x64/home/tunes/cl/THIRDPARTY/clon/termio/sbcl/foo.c:35:5:
warning: format ‘%d’ expects argument of type ‘int’, but argument 3
has type ‘long unsigned int’ [-Wformat=]
     fprintf (out, " %d)\n", sizeof(t.ws_row));
     ^
/home/tunes/.cache/common-lisp/sbcl-1.2.11.54-1ab7880-linux-x64/home/tunes/cl/THIRDPARTY/clon/termio/sbcl/foo.c:39:5:
warning: format ‘%d’ expects argument of type ‘int’, but argument 3
has type ‘long unsigned int’ [-Wformat=]
     fprintf (out, " %d\n", ((unsigned long)&(t.ws_col)) - ((unsigned
long)&(t)));
     ^
/home/tunes/.cache/common-lisp/sbcl-1.2.11.54-1ab7880-linux-x64/home/tunes/cl/THIRDPARTY/clon/termio/sbcl/foo.c:42:5:
warning: format ‘%d’ expects argument of type ‘int’, but argument 3
has type ‘long unsigned int’ [-Wformat=]
     fprintf (out, " %d)\n", sizeof(t.ws_col));
     ^
/home/tunes/.cache/common-lisp/sbcl-1.2.11.54-1ab7880-linux-x64/home/tunes/cl/THIRDPARTY/clon/termio/sbcl/foo.c:46:5:
warning: format ‘%d’ expects argument of type ‘int’, but argument 3
has type ‘long unsigned int’ [-Wformat=]
     fprintf (out, " %d\n", ((unsigned long)&(t.ws_xpixel)) -
((unsigned long)&(t)));
     ^
/home/tunes/.cache/common-lisp/sbcl-1.2.11.54-1ab7880-linux-x64/home/tunes/cl/THIRDPARTY/clon/termio/sbcl/foo.c:49:5:
warning: format ‘%d’ expects argument of type ‘int’, but argument 3
has type ‘long unsigned int’ [-Wformat=]
     fprintf (out, " %d)\n", sizeof(t.ws_xpixel));
     ^
/home/tunes/.cache/common-lisp/sbcl-1.2.11.54-1ab7880-linux-x64/home/tunes/cl/THIRDPARTY/clon/termio/sbcl/foo.c:53:5:
warning: format ‘%d’ expects argument of type ‘int’, but argument 3
has type ‘long unsigned int’ [-Wformat=]
     fprintf (out, " %d\n", ((unsigned long)&(t.ws_ypixel)) -
((unsigned long)&(t)));
     ^
/home/tunes/.cache/common-lisp/sbcl-1.2.11.54-1ab7880-linux-x64/home/tunes/cl/THIRDPARTY/clon/termio/sbcl/foo.c:56:5:
warning: format ‘%d’ expects argument of type ‘int’, but argument 3
has type ‘long unsigned int’ [-Wformat=]
     fprintf (out, " %d)\n", sizeof(t.ws_ypixel));
     ^
T

Revision history for this message
Faré (fahree) wrote :

Using %d on a long is undefined behavior, and the C compiler is allowed to reformat your hard disk and launch nuclear missiles targeted at you if you do it. Not that it will (I hope).

Here is a patch that addresses the issue, that also gets rid of a useless debug message from way back when.

Revision history for this message
Stas Boukarev (stassats) wrote :

Needs to be ensure that it does the right thing with win32's long-longs

Revision history for this message
Faré (fahree) wrote :

If you want, I can replace all the long's by long long's and %l by %ll... would you apply that?

Revision history for this message
Stas Boukarev (stassats) wrote :

I'm not sure what needs to be done, is the groveler actually requesting long-longs, or just longs.
There's a comment
#+nil"long long" ; TODO: doesn't exist in sb-alien yet
which is no longer true, it does exist.

Revision history for this message
Faré (fahree) wrote :

The groveler is mostly computing sizeof() and various named constants. It uses %d copiously (%ld with my patch), which assumes everything fits in a signed type. Some constants will definitely overflow.

Revision history for this message
Faré (fahree) wrote :

OK, how do I get this patch to go forward?

I believe using long long when printing (which is the case here) is always an improvement over using long: so far as I understand it, everything that would print fine as a long will still print fine as a long long, on any platform.

Revision history for this message
Faré (fahree) wrote :

OK, same patch, with long long instead of long, while we're at it.

Revision history for this message
Stas Boukarev (stassats) wrote :

Committed in 9c82161fd0aadfe35c4d930684f01ed832e7de5d, but there's still a problem with casting unsigned into signed.

Changed in sbcl:
status: New → Fix Committed
Stas Boukarev (stassats)
Changed in sbcl:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.