Article View: comp.os.os2.programmer
Article #214Re: Strange trap in IBM C Set/2
From: Brian Matusz
Date: Mon, 03 Aug 1992 14:05
Date: Mon, 03 Aug 1992 14:05
27 lines
1548 bytes
1548 bytes
In article <1992Aug3.111930.19189@ifi.unizh.ch> erzberg@ifi.unizh.ch (Martin Erzberger) writes:
>Can anybody see what's wrong with the following piece of code? I cut it
>down from a large utility which compiles and runs fine on a SUN.
>With the IBM C Set/2 compiles, it generates a TRAP. Looking with the
>debugger, the TRAP gets generated in the initialisation phase (I think
>at the moment the library gets called to initialize).
>When I remove any of the two declarations, the program will "run" (of
>course it does nothing).
>Now here the code:
>
>#include <stdlib.h>
>
>main(int argc, char *argv[])
>{
> char *test1 = NULL;
> int test2[32768];
>}
Not knowing for sure, but I'm asuming you're compiling 16-bit code ...
the 32k ints (at two bytes each) are 64k ... which is the size of your
data segment. Add the pointer and you've overflowed your data segment...
the initialization of the 32768th element of the integer array causes
you to try and access memory you don't own.
Just a guess ...
Brad Wilson (via a friend's account)
Technical Details
Message-ID:
<1992Aug3.140521.14803@vela.acs.oakland.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!usc!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!wsu-cs!vela!bcmatuszReferences:
<1992Aug3.111930.19189@ifi.unizh.ch>Show Full Headers
Complete Article Headers
Newsgroups: comp.os.os2.programmer Path: arc1-ca.pugleaf.net!sparky!uunet!usc!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!wsu-cs!vela!bcmatusz From: bcmatusz@vela.acs.oakland.edu (Brian Matusz) Subject: Re: Strange trap in IBM C Set/2 Message-ID: <1992Aug3.140521.14803@vela.acs.oakland.edu> Organization: Oakland University, Rochester MI. References: <1992Aug3.111930.19189@ifi.unizh.ch> Date: Mon, 3 Aug 1992 14:05:21 GMT Lines: 30