The No.1 rule in C/C++ programming is: never touch any memory that
are not allocated by your program, even if it is a single byte. Yes, the
program may not segfault immediately when your program accesses
memory beyond its boundary. But it can cause catastrophe later, such
as airplane crashes. ;-) Google "Smash the stack for fun and profit",
you will get more ideas on the unpleasant result.
A good practice is: always initialize a pointer with NULL value, assign
it with the memory by malloc/realloc later. after free it, always reset it
to NULL value. Thus, if your program accidentally access the pointer
after freeing the memory it pointed to, you get segfault immediately.
And then you know there is a bug in the program.
On Mon, Oct 20, 2008 at 6:12 AM, jehan <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> in a C program, does the program send a SIGSEV signal (so ends with a
> "Segmentation fault") immediately when you try to read or write in a
> non-allocated memory, or does it do so only when it reads/writes in a
> forbidden location, allocated for another program? What I means is: if you
> go out of your allocated memory, but this segment belongs to no other
> processus, then will it segfault?
>
> I am trying to understand such a violation in the utf-8 branch, I found the
> line where it segfaults with valgring/gdb, but don't manage to find why the
> pointer was not allocated (my first verification seem to conclude it should
> be allocated), and why it does not always segfault to the same line/column
> for the exact same action.
>
> And for gdb experts (or valgrind, or any other debugging program), do you
> know if it is possible to focus on one pointer-variable, and follow its
> memory allocation/liberation and size in the program run?
> Thanks.
>
> Jehan
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Materm-devel mailing list
> Materm-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/materm-devel
> mrxvt home page: http://materm.sourceforge.net
>
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Materm-devel mailing list
Materm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/materm-devel
mrxvt home page: http://materm.sourceforge.net