Skip to content

Commit

Permalink
Add error handling in log_print
Browse files Browse the repository at this point in the history
Failure of log open/create wasn't handled.
  • Loading branch information
hfiref0x committed Jan 24, 2019
1 parent 2ae73af commit 9ac3ba8
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions al-khaser/Shared/log.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "pch.h"
#include "log.h"

FILE *fp;
static int SESSION_TRACKER; //Keeps track of session

TCHAR* print_time()
Expand Down Expand Up @@ -47,12 +46,19 @@ void log_print(const TCHAR* filename, const TCHAR *fmt, ...)
const TCHAR *p, *r;
int e;

FILE *fp = NULL;
errno_t error;

TCHAR *pszTime;

if (SESSION_TRACKER > 0)
_tfopen_s(&fp, _T("log.txt"), _T("a+"));
error = _tfopen_s(&fp, _T("log.txt"), _T("a+"));
else
_tfopen_s(&fp, _T("log.txt"), _T("w"));
error = _tfopen_s(&fp, _T("log.txt"), _T("w"));

// file create/open failed
if ((error != 0) || (fp == NULL))
return;

pszTime = print_time();
if (pszTime) {
Expand Down

0 comments on commit 9ac3ba8

Please sign in to comment.