Xref: utzoo news.admin:3872 news.software.b:1735 Path: utzoo!attcan!uunet!husc6!bloom-beacon!apple!bionet!agate!helios.ee.lbl.gov!lll-tis!oodis01!uplherc!sp7040!obie!wes From: wes@obie.UUCP (Barnacle Wes) Newsgroups: news.admin,news.software.b Subject: Re: bugfix for inews (control messages cause coredump) Summary: How about error AND no error on the SAME system? Message-ID: <252@obie.UUCP> Date: 4 Nov 88 06:58:34 GMT References: <5686@fluke.COM> <5695@fluke.COM> <6266@claris.com> <25995@tut.cis.ohio-state.edu> Organization: the Well of Souls Lines: 48 In article <25995@tut.cis.ohio-state.edu>, karl@triceratops.cis.ohio-state.edu (Karl Kleinpaste) writes: > Tut == Pyramid 98x: > > [135] [1:59pm] tut:/dino0/karl/tmp> cat > z.c > main() > { > char *p = (char *)0; > p++; > *p = 'p'; > printf("done\n"); > } > [136] [1:59pm] tut:/dino0/karl/tmp> cc z.c -o z > [137] [2:00pm] tut:/dino0/karl/tmp> ./z > Bus error (core dumped) Here are the results for System V/AT ('286): obie!wes[44] cat z.c main() { char *p = (char *)0; p++; *p = 'p'; printf("done\n"); } obie!wes[45] time cc -o z z.c 2.4u 4.1s 0:10 64% obie!wes[45] ./z done obie!wes[46] time cc -o z -Ml z.c # use "large memory model" 2.8u 3.9s 0:11 60% obie!wes[47] ./z ./z: Segmentation violation -- Core dumped obie!wes[48] rm core z z.c Neat, huh? This is why: using the small memory model (the default), pointers are 16-bit offsets into the data segments. Addresses DS:0 and DS:1 are valid, writable addresses, so the program runs correctly in small model. In the large model, however, pointers are 32 bits, and include the segment selector. This makes (char *)0 equal address 0:0, which may or may not be a valid address in the process' space. If it is a valid address, it is probably in the code segment, which CANNOT be writable on the '286. This system can really be a nightmare to port to! -- "The whole problem with the world is that fools and fanatics are always so certain of themselves, but wiser people so full of doubts." - Bertrand Russell "How come he didn't put `I think' at the end of it?" - James P. Hogan