Re: [NEWBIE] Limits of stuff

From: Ron Hensley (ron@CROSS.DMV.COM)
Date: 03/04/98


On Wed, 4 Mar 1998, Chuck Reed wrote:

> was wondering exactly how much a char *somthing could hold.  I'm mainly

The trick is, char *, is a pointer. Its a variable holding an address of
a place in memory. as its a Char pointer, the C compiler happily assumes
this address points to a place in memory where some 1 byte characters are
stored, in a row, ending with a NULL byte to signify the end.

Thats why:


  void main(void) {
    char *buf;

    printf(buf,"Hello\n");
  }

is a HUGE booboo. Buf is a pointer. Its not pointing anywhere yet, as its
not been pointed anywhere, so you are asking the compiler to write
 h-e-l-l-o-\n-NULL
to the spot in memory where it happends to point, beginning of memory,
address 0, or god knows where, perhaps in this case.

usually this is how people end up overwriting there own code in memory,
or even the operating itself and causing a nice big crash.

Another common problem is to try to read from or copy from a non
initilized pointer. As C will keep right on happily reading till it finds
a NULL byte. If you start reading from lala land, this could be like 5
million bytes later, or 1 byte later, whom knows


    *******************************************************************
    *   Ron Hensley                     ron@dmv.com                   *
    *   Network Administrator           http://www.dmv.com/~ron       *
    *                                   PGP Key at WWW Page           *
    *   DelMarVa OnLine                 749-7898 Ext. 403             *
    *******************************************************************


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST