www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/09/08/01:20:35

Xref: news2.mv.net comp.os.msdos.djgpp:8393
From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: HELP MEEEEEE!!!!
Date: Sat, 07 Sep 1996 22:12:31 -0700
Organization: Three pounds of chaos and a pinch of salt
Lines: 41
Message-ID: <323255BF.65C0@cs.com>
References: <01bb9627.474de9c0$146332cc AT robmatthews> <32289180 DOT 543D AT cs DOT com> <01bb97cb$5b601780$4dfb5380 AT maan-m DOT -hamze> <50k7f2$c9f AT epx DOT cis DOT umn DOT edu> <842092690snz AT tsys DOT demon DOT co DOT uk>
NNTP-Posting-Host: ppp216.cs.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Tom Wheeley wrote:
>
> OK, then I want my program to return struct foo, and I want the command line
> in one long string.
> 
> struct foo main(char *cmdline);
> 
> Do you think this will work?

Hehe... I like that example.  :)  If I have reckoned correctly, this is what
the above code will produce:

1) Any attempt to access cmdline will probably cause a SIGSEGV due to NULL
pointer dereference.  This is because the int-sized pointer represented by
cmdline will actually be passed the value of argc, which likely is a single
digit integer, and CWSDPMI barfs on accessing memory below 1K.)  However,
under any DPMI that doesn't support NULL pointer protection, code which
attempts to use cmdline will start merrily playing with the innards of the
computer's OS and probably cause all manner of hard crashes and other
problems, like reformatting the hard drive.  

2) When main() exits, that struct foo will actually be resolved as a pointer
to a temporary block of static memory (or memory allocated from the stack; I
don't remember which).  So the 4-byte value returned in eax will be the
address of this block, and the (AFAIK) 1-byte return code to the OS will be
the lower 1 byte of this address.  This won't cause any hard crashes, but
will play merry havoc with any program which depended on the return value
for further processing.

Remember - the ANSI standard exists for a reason!  You play with it at your
own risk!

John

-- 
--------------------------------------------------------------------------
|  John M. Aldrich, aka Fighteer I   |         fighteer AT cs DOT com           |
|     *  Proud user of DJGPP!  *     |    http://www.cs.com/fighteer     |
|       ObJoke:  If Bill Gates were a robber, not only would he          |
|        shoot you, but he'd send you a bill for the bullets.            |
--------------------------------------------------------------------------

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019