Ich mache einen Makefile Creator, aber ich bin in diesem Fehler auf Sprintf stecken, ist die kurioseste Sache, dass ich mehrere Sprintf vor dem einen mit dem Fehler haben und sie funktionieren gut.Segmentation Fault mit Sprintf
Hier ist der Code:
if (WIFEXITED(stat) ){
if (WEXITSTATUS(stat)) {
if (cFiles == 0 && cFolders == 0) {
Crear(path);
}
cFolders = 1;
TEMP = malloc(sizeof(char)*(strlen(direntp->d_name) + 25));
if (TEMP == NULL) {
perror("Malloc Error: ");
exit(1);
}
if (sprintf(TEMP, "\n%s/%s.a: force\n\t$(MAKE) -C %s\n",direntp->d_name, direntp->d_name, direntp->d_name) < 0) {
perror("Sprintf Error: ");
exit(1);
}
write(STDOUT_FILENO,TEMP,strlen(TEMP));
f.name = malloc(sizeof(char)*(strlen(direntp->d_name)*2 + 3));
if (f.name = NULL) {
perror("Malloc Error: ");
exit(1);
}
//This is the one with the problem!!!
if (sprintf(f.name, "%s/%s.a", direntp->d_name, direntp->d_name) < 0) {
perror("Sprintf Error: ");
exit(1);
}
l = AddToList(l,&f);
}
}
Meine beste Schätzung ist, dass eine der Zeichenfolgen nicht null terminiert ist. Ich hatte dieses Problem einige Male, als ich zum ersten Mal C. lernte. – forivall