🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.windows.x
Article #38399

Solved: XtNextEvent corrupting stack?

#38399
From: Bill Shirley [CSC]
Date: Thu, 21 May 1992 19:58
68 lines
3314 bytes
**** CROSSPOST: Followup -> gnu.gcc.help

In article <1992May21.105156@gothamcity.jsc.nasa.gov>, shirley@gothamcity.jsc.nasa.gov (Bill Shirley [CSC]) writes:
|> The following is a stack trace of my program execution:
|> 
|> (gdb) step
|> 304         guiDoEvent();               /* handle one interface event */
|> (gdb)
|> guiDoEvent () at ./sys/gui.c:120
|> 120       XtNextEvent(&event);
|> (gdb) where
|> #0  guiDoEvent () at ./sys/gui.c:120
|> #1  0x1b56c in supEventLoop () at ./sys/supervisor.c:304
|> #2  0x1b3e0 in supWorkExercises () at ./sys/supervisor.c:255
|> #3  0x1b20c in supHandleStudents () at ./sys/supervisor.c:188
|> #4  0x1b088 in main (argc=1, argv=0xf7fffb44) at ./sys/supervisor.c:134
|> (gdb) next
|> 121       XtDispatchEvent(&event);
|> (gdb) where
|> #0  guiDoEvent () at ./sys/gui.c:121
|> #1  0x1b56c in supEventLoop () at ./sys/supervisor.c:304
|> 
|> 
|> It seems that XtNextEvent is destroying my stack.
|> Is this caused by X?
|> I've never waited until 5 function calls deep to use  XtNextEvent.
|> This  shouldn't be a problem, but my eyes tell differently.
|> Is this actually a compiler (gcc) or a machine (SPARCstation 2) problem?
|> Could something else be corrupting my stack, but no show immediately in gdb?
|> How does the bottom of the stack get corrupted?
|> 
|> Obviously this causes a bit of pain when supEventLoop tries to return
|> execution to its caller. (i.e. Segmentation fault)
|> 
|> Help me, I'm melting...
|> 

Ouch!

I found the problem.  The following code is evil:

XEvent          *event;

  XtNextEvent(&event);
  XtDispatchEvent(&event);


It destroyed the bottom of my stack, bad code, bad code!
(The XEvent structure being ~24 bytes and a pointer being ~4 bytes, this
 can tend to write all over your execution stack. In my case obliterating
 the return address)

Which got me to thinking...

 ``Why didn't -DNeedFunctionPrototypes=1 make the compiler scream at me?''

I recompiled it, with the erroneous code, to see if I had ignored my
omniscient compilers warning.  But, low and behold, it had no complaint.

gcc -g -DDEBUG -DNeedFunctionPrototypes=1 -Wall -c file.c

Did not elicit even a warning when I compiled the code that sent an incorrect
parameter.  Why, oh, why did it not warn me?
-- 
Bill Shirley
shirley@krakatoa.jsc.nasa.gov
(PS. I didn't write this code, it must of been my evil twin ;-)
Technical Details
Message-ID: <1992May21.145811@gothamcity.jsc.nasa.gov>
Path: arc1-ca.pugleaf.net!sparky!uunet!europa.asd.contel.com!darwin.sura.net!jvnc.net!yale.edu!qt.cs.utexas.edu!cs.utexas.edu!bcm!aio!shirley
References: <1992May21.105156@gothamcity.jsc.nasa.gov>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,badd1a95a3bd2192,start
X-Google-Attributes: gid11318c,public
X-Google-Thread: 103734,badd1a95a3bd2192,start
X-Google-Attributes: gid103734,public
X-Google-ArrivalTime: 1992-05-21 07:32:04 PST
Path: arc1-ca.pugleaf.net!sparky!uunet!europa.asd.contel.com!darwin.sura.net!jvnc.net!yale.edu!qt.cs.utexas.edu!cs.utexas.edu!bcm!aio!shirley
From: shirley@gothamcity.jsc.nasa.gov (Bill Shirley [CSC])
Newsgroups: comp.windows.x,gnu.gcc.help
Subject: Solved: XtNextEvent corrupting stack?
Keywords: XtNextEvent gcc SunOS sparc
Message-ID: <1992May21.145811@gothamcity.jsc.nasa.gov>
Date: 21 May 1992 19:58:11 GMT
References: <1992May21.105156@gothamcity.jsc.nasa.gov>
Sender: news@aio.jsc.nasa.gov (USENET News System)
Followup-To: gnu.gcc.help
Organization: Software Technology Lab - NASA/Johnson Space Center
Lines: 68