From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 102b75,85404311f8041f7a X-Google-Attributes: gid102b75,public X-Google-Thread: 1164f8,5747331edea7cbab X-Google-Attributes: gid1164f8,public X-Google-ArrivalTime: 2001-07-18 09:27:56 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!cpk-news-hub1.bbnplanet.com!news.gtei.net!dca6-feed1.news.digex.net!sfo2-feed1.news.digex.net!intermedia!lynx.unm.edu!news.NMSU.Edu!not-for-mail From: Joe Pfeiffer Newsgroups: comp.sys.dec,comp.arch Subject: Re: using memory beyond the "top" of stack Date: 18 Jul 2001 10:13:59 -0600 Organization: NMSU Computer Science Message-ID: <1b8zhmb4fs.fsf@cs.nmsu.edu> References: <994616870.688233@haldjas.folklore.ee> <9iuka3$rku$1@mach.thp.univie.ac.at> <9j0jts$r2u$1@sword.avalon.net> <1bn163xzf0.fsf@cs.nmsu.edu> <995458767.205555@haldjas.folklore.ee> <9j45pg$7qe$1@sunnews.cern.ch> <995470891.294985@haldjas.folklore.ee> NNTP-Posting-Host: viper.cs.nmsu.edu X-Trace: bubba.NMSU.Edu 995472842 13274 128.123.64.113 (18 Jul 2001 16:14:02 GMT) X-Complaints-To: usenet@bubba.NMSU.Edu NNTP-Posting-Date: 18 Jul 2001 16:14:02 GMT X-Newsreader: Gnus v5.7/Emacs 20.5 Xref: archiver1.google.com comp.sys.dec:5982 comp.arch:14258 Sander Vesik writes: > In comp.arch Dan Pop wrote: > > In <995458767.205555@haldjas.folklore.ee> Sander Vesik writes: > > >>In comp.arch Joe Pfeiffer wrote: > >> > >>> Real fun was porting VAX to Sun. I honestly thought C specified that > >>> a NULL pointer was an empty string. Passing a pointer to an int with > >>> a value of less than 256 to a function expecting a pointer to a char > >>> was a good one, too. > >> > >>Funny there is a lot of code developed on Linux that assumes just that > >>about NULL and empty strings... > > > Let's see: > > > ues12:~/tmp 81> uname -a > > Linux ues12 2.2.12-20 #1 Mon Sep 27 10:40:35 EDT 1999 i686 unknown > > ues12:~/tmp 82> cat test.c > > #include > > > int main(void) > > { > > return strlen(NULL); > > } > > ues12:~/tmp 83> gcc test.c > > ues12:~/tmp 84> ./a.out > > Segmentation fault > > > Next time, you may want to actually check your facts. Oh, sorry, I > > forgot, this is Usenet, where no "serious" poster cares about facts ;-) > > Take a look at what the following one gives you: > > #include > > main() > { > printf(NULL); > printf("%s\n",NULL); > } > > But of course, you are welcome to continue assuming that linux always > does everything right and couldn't possibly be wrong in anything. It's certainly true that some string functions in the C library -- notably printf, as you pointed out -- do a test for NULL and don't break. But as the other poster pointed out, the pointer is still invalid, and there are other string functions that assume the programmer knows what he or she is doing (like I didn't when I ran into this, lo these many years ago), and the program will crash. I have absolutely no idea what your comment about assuming Linux does everything right could be referring to; when I ran into the problem, it was porting from 4.2BSD on a VAX (where the bottom page is readable, and coincidentally address 0 always contained a 0 byte), to a reasonably early SunOS on a 680x0 (where the bottom page isn't readable). -- Joseph J. Pfeiffer, Jr., Ph.D. Phone -- (505) 646-1605 Department of Computer Science FAX -- (505) 646-1002 New Mexico State University http://www.cs.nmsu.edu/~pfeiffer SWNMRSEF: http://www.nmsu.edu/~scifair