improve error handling to make coverity scan happy
This commit is contained in:
@ -127,12 +127,15 @@ void ReadCarFile(void)
|
|||||||
|
|
||||||
/* First pass through file -- Count molecules */
|
/* First pass through file -- Count molecules */
|
||||||
|
|
||||||
while(fgets(line,MAX_LINE_LENGTH,CarF) != NULL )
|
while (fgets(line,MAX_LINE_LENGTH,CarF) != NULL )
|
||||||
if( strncmp(line,"end",3) == 0 )
|
if (strncmp(line,"end",3) == 0 )
|
||||||
no_molecules++;
|
no_molecules++;
|
||||||
|
|
||||||
/* Allocate space to keep track of the number of atoms within a molecule */
|
/* 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));
|
no_atoms = (int *) calloc(no_molecules,sizeof(int));
|
||||||
if ( no_atoms == NULL ) {
|
if ( no_atoms == NULL ) {
|
||||||
printf("Could not allocate memory for no_atoms\n");
|
printf("Could not allocate memory for no_atoms\n");
|
||||||
|
|||||||
@ -12,6 +12,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#define strdup(x) _strdup(x)
|
#define strdup(x) _strdup(x)
|
||||||
@ -91,10 +92,14 @@ void SearchAndFill(struct FrcFieldItem *item)
|
|||||||
}
|
}
|
||||||
|
|
||||||
file_pos = ftell(FrcF);
|
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 */
|
/* Count the number of lines until next item is found */
|
||||||
|
|
||||||
while( strncmp(fgets(line,MAX_LINE_LENGTH,FrcF), "#", 1) != 0 )
|
while (strncmp(fgets(line,MAX_LINE_LENGTH,FrcF), "#", 1) != 0 )
|
||||||
ctr++;
|
ctr++;
|
||||||
|
|
||||||
/* Allocate the memory using calloc */
|
/* Allocate the memory using calloc */
|
||||||
@ -110,7 +115,10 @@ void SearchAndFill(struct FrcFieldItem *item)
|
|||||||
|
|
||||||
/* Read lines until keyword is found */
|
/* 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");
|
strcpy(line,"empty");
|
||||||
|
|
||||||
/* Read lines until data starts (when !--- is found) */
|
/* Read lines until data starts (when !--- is found) */
|
||||||
|
|||||||
Reference in New Issue
Block a user