Bug 8757 - GCC crash when sizeof (long) > sizeof (char *), (splay_tree_compare_fn)strcmp is wrong
Summary: GCC crash when sizeof (long) > sizeof (char *), (splay_tree_compare_fn)strcmp...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: other (show other bugs)
Version: 3.2
: P3 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2002-11-29 08:26 UTC by mitr
Modified: 2016-04-05 22:28 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-09-24 17:09:30


Attachments
gcc-patch (882 bytes, text/plain)
2003-05-21 15:17 UTC, mitr
Details

Note You need to log in before you can comment on or make changes to this bug.
Description mitr 2002-11-29 08:26:00 UTC
In several places, (splay_tree_compare_fn)strcmp
is passed to splay_tree_new (). But the compare
function is defined with two "long" arguments,
and when sizeof (long) > sizeof (char *), strcmp
uses the lower and upper half of the first "long"
argument as pointers, and GCC crashes. Attached patch
fixes all occurences in gcc-core-3.2, there may be more
in other frontends.
BTW, AFAIK it is not guaranteed that 'long' is long
enough to hold a pointer.

Release:
gcc-3.2, current (Nov 29 2002) CVS HEAD
Comment 1 Wolfgang Bangerth 2003-03-15 18:44:31 UTC
State-Changed-From-To: open->feedback
State-Changed-Why: Do you have a small testcase that triggers the bug, so that
    we can see whether the patch is indeed necessary? I can
    confirm that the patch has at least not been applied by
    someone.
    
    Thanks
      Wolfgang
Comment 2 mitr 2003-03-15 20:07:54 UTC
From: Miloslav Trmac <mitr@volny.cz>
To: bangerth@dealii.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org,
	nobody@gcc.gnu.org, gcc-gnats@gcc.gnu.org
Cc:  
Subject: Re: other/8757: GCC crash when sizeof (long) > sizeof (char *), (splay_tree_compare_fn)strcmp is wrong
Date: Sat, 15 Mar 2003 20:07:54 +0100

 Hello,
 On Sat, Mar 15, 2003 at 06:44:31PM -0000, bangerth@dealii.org wrote:
 >     Do you have a small testcase that triggers the bug, so that
 >     we can see whether the patch is indeed necessary? I can
 >     confirm that the patch has at least not been applied by
 >     someone.
 Not really, since it involves setting up an environment where
 sizeof (long) > sizeof (char *). In that environment,
 gcc would crash compiling even trivial "hello, world".
 
 In my case, it was http://www.fw.cz/~mitr/maxos.html
 (snapshot available at http://carolina.mff.cuni.cz/~trmac/MaxOS,
 including patched gcc). If someone would like to reproduce this
 independently, I can dig up the necessary gcc patches (new
 target OS) and create "before" and "after" iso images.
 
 The patch seems obvious to me though ;-)
 	Mirek
Comment 3 Dara Hazeghi 2003-06-02 04:54:08 UTC
Hello,

if you're confident of the correctness of your patch, could you please post it to the gcc-patches 
mailing list (after ensuring that it still works with current sources). That way, somebody with the 
power to include your patch will probably actually see it. Thanks,

Dara
Comment 4 Andrew Pinski 2003-06-27 01:52:08 UTC
Your patch is not correct but it still exists on the mainline (20030626).
The correct fix is to change the type splay_tree_key to be the same size of void*.
Comment 6 Manuel López-Ibáñez 2016-04-05 22:28:55 UTC
It seems this was fixed a long time ago. Oldest ICE-on-valid!