Remove close/reopen logic for file handle and fix Ecc crash on empty

This commit is contained in:
Robert MacGregor 2016-03-12 17:20:41 -05:00
parent 9f50d3ef84
commit 609d71437f

View File

@ -239,7 +239,7 @@ enum ESStatus
}; };
/* Determine whether or not our target ES file is indeed valid input. */ /* Determine whether or not our target ES file is indeed valid input. */
ESStatus GetESStatus(char *filename) ESStatus GetESStatus()
{ {
ESStatus result = ESStatus::Empty; ESStatus result = ESStatus::Empty;
@ -249,7 +249,7 @@ ESStatus GetESStatus(char *filename)
char* temporaryBuffer = (char*)malloc(length); char* temporaryBuffer = (char*)malloc(length);
fseek(_fInput, 0, SEEK_SET); fseek(_fInput, 0, SEEK_SET);
fread(temporaryBuffer, length, 1, _fInput); fread(temporaryBuffer, length, 1, _fInput);
fclose(_fInput); fseek(_fInput, 0, SEEK_SET);
// Loop through each line // Loop through each line
char* currentSequence = strtok(temporaryBuffer, "\n"); char* currentSequence = strtok(temporaryBuffer, "\n");
@ -315,18 +315,11 @@ ESStatus GetESStatus(char *filename)
result = ESStatus::Good; result = ESStatus::Good;
free(temporaryBuffer); free(temporaryBuffer);
if (result == ESStatus::Good)
_fInput = FOpen(filename, "r");
return result; return result;
} }
} }
while(currentSequence = strtok(NULL, "\n")); while(currentSequence = strtok(NULL, "\n"));
free(temporaryBuffer);
if (result == ESStatus::Good)
_fInput = FOpen(filename, "r");
return result; return result;
} }
@ -388,7 +381,7 @@ int main(int argc, char *argv[])
_fInput = FOpen(argv[1], "r"); _fInput = FOpen(argv[1], "r");
// Make sure we're loading a valid ES file // Make sure we're loading a valid ES file
ESStatus status = GetESStatus(argv[1]); ESStatus status = GetESStatus();
switch (status) switch (status)
{ {