mirror of
https://github.com/ptitSeb/Serious-Engine
synced 2024-11-22 10:20:26 +01:00
Merge pull request #16 from Ragora/EccFixBase
Remove close/reopen logic for file handle and fix Ecc crash on empty
This commit is contained in:
commit
0a3be0bca5
|
@ -239,17 +239,26 @@ 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;
|
||||||
|
|
||||||
// Read a temporary buffer of the entire file contents
|
// Read a temporary buffer of the entire file contents
|
||||||
fseek(_fInput, 0, SEEK_END);
|
fseek(_fInput, 0, SEEK_END);
|
||||||
size_t length = ftell(_fInput);
|
size_t length = ftell(_fInput);
|
||||||
|
|
||||||
|
// Hard-stop on Empty out of paranoia
|
||||||
|
if (length == 0)
|
||||||
|
return result;
|
||||||
|
|
||||||
char* temporaryBuffer = (char*)malloc(length);
|
char* temporaryBuffer = (char*)malloc(length);
|
||||||
|
|
||||||
|
if (!temporaryBuffer)
|
||||||
|
return ESStatus::Error;
|
||||||
|
|
||||||
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 +324,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,14 +390,21 @@ 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)
|
||||||
{
|
{
|
||||||
case ESStatus::Empty:
|
case ESStatus::Empty:
|
||||||
|
{
|
||||||
|
fclose(_fInput);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
case ESStatus::Error:
|
case ESStatus::Error:
|
||||||
|
{
|
||||||
|
fclose(_fInput);
|
||||||
|
printf("Ecc encountered an error during the es verification.\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//printf("%s\n", argv[1]);
|
//printf("%s\n", argv[1]);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user