fixed possible segfault in writeLog
This would happen if initLogger returned INVALID_FILE and you still tried using writeLog
This commit is contained in:
parent
385f39b05d
commit
ee886f0237
@ -86,6 +86,12 @@ logFile initLogger(char *directoryPath)
|
|||||||
|
|
||||||
void writeLog(int loggerFile, char *logMessage)
|
void writeLog(int loggerFile, char *logMessage)
|
||||||
{
|
{
|
||||||
|
//CHECK IF loggerFile IS CREATED
|
||||||
|
if (loggerFile == INVALID_FILE)
|
||||||
|
{
|
||||||
|
return; //TODO: Add some kind of error message
|
||||||
|
}
|
||||||
|
|
||||||
//VARIABLES
|
//VARIABLES
|
||||||
char *buffer = malloc(strlen(WRITE_FORMAT) + strlen(logMessage) + 2);
|
char *buffer = malloc(strlen(WRITE_FORMAT) + strlen(logMessage) + 2);
|
||||||
time_t timeL = time(NULL);
|
time_t timeL = time(NULL);
|
||||||
@ -93,7 +99,7 @@ void writeLog(int loggerFile, char *logMessage)
|
|||||||
|
|
||||||
sprintf(buffer, WRITE_FORMATTING, tm.tm_hour, tm.tm_min, tm.tm_sec, logMessage); //LOAD MESSAGE
|
sprintf(buffer, WRITE_FORMATTING, tm.tm_hour, tm.tm_min, tm.tm_sec, logMessage); //LOAD MESSAGE
|
||||||
|
|
||||||
if (write(loggerFile, buffer, strlen(buffer)) == 0) abort(); //WRITE (YAY) //TODO: Make it safe
|
write(loggerFile, buffer, strlen(buffer)); //WRITE (YAY)
|
||||||
|
|
||||||
//DEALLOCATION
|
//DEALLOCATION
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user