improve error handling to make coverity scan happy

This commit is contained in:
Axel Kohlmeyer
2023-12-02 08:53:05 -05:00
parent 4035291a48
commit cace83e30d
2 changed files with 16 additions and 5 deletions

View File

@ -132,7 +132,10 @@ void ReadCarFile(void)
no_molecules++;
/* Allocate space to keep track of the number of atoms within a molecule */
if (no_molecules < 1) {
fprintf(stderr, "No molecules in system");
exit(32);
}
no_atoms = (int *) calloc(no_molecules,sizeof(int));
if ( no_atoms == NULL ) {
printf("Could not allocate memory for no_atoms\n");

View File

@ -12,6 +12,7 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#if defined(_WIN32)
#define strdup(x) _strdup(x)
@ -91,6 +92,10 @@ void SearchAndFill(struct FrcFieldItem *item)
}
file_pos = ftell(FrcF);
if (file_pos < 0) {
fprintf(stderr, "Could not obtain file stream position: ", strerror(errno));
exit(2);
}
/* Count the number of lines until next item is found */
@ -110,7 +115,10 @@ void SearchAndFill(struct FrcFieldItem *item)
/* Read lines until keyword is found */
fseek(FrcF,file_pos,SEEK_SET);
if (fseek(FrcF,file_pos,SEEK_SET) < 0) {
fprintf(stderr, "Resetting file stream failed: ", strerror(errno));
exit(2);
}
strcpy(line,"empty");
/* Read lines until data starts (when !--- is found) */