Why am i getting buffer overflow?


#1

int isPalindrome(char* A) {
char* temp = (char*) malloc(strlen(A)*sizeof(char));
int index = 0;
int i;
for ( i=0; i<strlen(A); i++){
if (isalnum(A[i])){
temp[index] = tolower(A[i]);
index++;
}
}
for (i=0; i<strlen(temp)/2; i++){
if (temp[i] != temp[strlen(temp)-i-1]){
return 0;
}
}
free(temp);
return 1;
}