glibc detected malloc(): memory corruption in C
问题 I am trying to compile and code written in C under linux, and got this error message: glibc detected malloc(): memory corruption and I cannot find out why... the substring() just return you part of the original string by giving the starting index and length. e.g. substring("this is example",0,4) = "this"; char *substring(char* str, int start, int length) { char *newString = (char *)malloc(length * sizeof(char)); int i, x = 0; int end=start+length-1; for(i = start ; i <= end; i++){ newString[x