Skip to content

Commit ce4e041

Browse files
authored
Check time and localtime during compile (#2933)
Signed-off-by: Mike Essenmacher <[email protected]>
1 parent 0931985 commit ce4e041

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/Compiler/CompilerUtils.cpp

+9-6
Original file line numberDiff line numberDiff line change
@@ -170,18 +170,21 @@ int Command::exec(std::string wdir) const {
170170
}
171171

172172
void showCompilePhase(std::string msg) {
173-
time_t rawTime;
173+
time_t rawTime = 0;
174174
struct tm *timeInfo;
175-
char buffer[80];
175+
char buffer[80] = "";
176176
// Remember first time.
177177
static time_t firstRawTime;
178178
static bool hasFirstRawTime = false;
179179

180180
// Get current date.
181-
time(&rawTime);
182-
timeInfo = localtime(&rawTime);
183-
strftime(buffer, 80, "%c", timeInfo);
184-
std::string currentTime(buffer);
181+
std::string currentTime("");
182+
if (time(&rawTime) == -1 || (timeInfo = localtime(&rawTime)) == NULL ||
183+
(strftime(buffer, 80, "%c", timeInfo)) == 0) {
184+
currentTime = "Error obtaining current time";
185+
} else {
186+
currentTime = buffer;
187+
}
185188

186189
// Compute time difference in seconds.
187190
int diff = 0;

0 commit comments

Comments
 (0)