strncpy leading to segmentation fault

I could point you to man pages, websites, etc, but ultimately what matters is the C standard itself. As part of the standard runtime library, the usage and behavior is defined in C99-§7.23.2.4 as: #include <string.h> char *strncpy(char * restrict s1, const char * restrict s2, size_t n); Description The strncpy function copies not more … Read more

strlen not checking for NULL

The rational behind it is simple — how can you check the length of something that does not exist? Also, unlike “managed languages” there is no expectations the run time system will handle invalid data or data structures correctly. (This type of issue is exactly why more “modern” languages are more popular for non-computation or … Read more

Segfaults in malloc() and malloc_consolidate()

From http://www.gnu.org/s/libc/manual/html_node/Heap-Consistency-Checking.html#Heap-Consistency-Checking: Another possibility to check for and guard against bugs in the use of malloc, realloc and free is to set the environment variable MALLOC_CHECK_. When MALLOC_CHECK_ is set, a special (less efficient) implementation is used which is designed to be tolerant against simple errors, such as double calls of free with the same … Read more