[prog] Segmentation fault :-(

Kathryn Hogg kjh at flyballdogs.com
Tue Sep 24 10:47:08 EST 2002


> Ah, right.  Yes, if data is too big then that can certainly cause
> problems.  See if you are limited in your allowed data segment size. To
> do this on a *nix machine type "ulimit -a" at the prompt.  You should
> get something like:
>
> core file size (blocks)     unlimited
> data seg size (kbytes)      131072
> file size (blocks)          unlimited
> max memory size (kbytes)    1019872
> open files                  4096
> pipe size (512 bytes)       8
> stack size (kbytes)         2048
> cpu time (seconds)          unlimited
> max user processes          64
> virtual memory (kbytes)     1048576

That probably isn't the problem for a couple of reasons.  It sounds like
the character array is probably declared as a global or local variable and
not via operator new.  If it is declared as local variable, it would be
put on the stack and not in the data segment.

Also, until we actually dereference the pointer in recv(), it doesn't
really matter what it is because it's just a pointer. So even if it was 0,
her program would still make it into recv() and hopefully die there.

Of course what we don't know is how many times has BaseSocket::recv been
called?


> assert.h provides the assert function.  If the test is false it'll kill
> your program and provide you a useful error message.  I found it a very
> handy debugging technique.  Much tidier than:
> if(data == NULL)
> {
>      fprintf(STDERR, "data is NULL at line 1234\n";
>      exit(1);
> }
> especially because it saves you from worrying about moving line numbers.
> ;)


Not a problem, just do:


> Just a quick warning though, my call to assert looks very wrong to me.
> I'm telling myself that it's just my allergy to naked variables and
> barewords from doing too much Perl, but I'm not sure.  It may indeed be
> wrong.  If so, you'll have to read the man pages.
>
>
>> Yes ,  I can cope with RTFM. :-)
>> RTFM is sometimes followed by where in th FM, so that's sometimes
>> helpful; Otherwise I go back and RTFM, and ignore the person who told
>> me to! :-))
>
> :)  FM references are usually provided.  You'll see.
>
>
> 	Jacinta
>
>
> --
>    ("`-''-/").___..--''"`-._          |  Jacinta Richardson	    |
>     `6_ 6  )   `-.  (     ).`-.__.`)  |  Perl Training Australia    |
> (_Y_.)'  ._   )  `._ `. ``-..-'   |      +613 9354 6001 	    |
>   _..`--'_..-_/  /--'_.' ,'           | contact at perltraining.com.au |
> (il),-''  (li),'  ((!.-'              |   www.perltraining.com.au   |
>
>
> _______________________________________________
> Programming mailing list
> Programming at linuxchix.org
> http://www.linuxchix.org/mailman/listinfo/programming


-- 
Kathryn





More information about the Programming mailing list