Why would the following C code not produce a segmetation fault? And what is actually happening in the data locations and pointers?
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main (){
char *str;
str = (char*) malloc(8);
strcpy(str, "CM10228");
printf("String = %s %u\n", str, str);
strncat(str, " is the best.",12);
printf("String = %s %u\n", str, str);
free(str);
return(0);
}
When would a segmentation fault arise?