add null checks for two more unchecked calls to localtime(), just in case

This commit is contained in:
Tomasz Śniatowski 2008-04-12 20:11:03 +01:00
parent 36d2ee8cd9
commit c0905047b4
2 changed files with 13 additions and 6 deletions

View file

@ -546,10 +546,14 @@ Units cannot be killed by poison alone. The poison will not reduce it below 1 HP
case REPORT_CLOCK: {
time_t t = time(NULL);
struct tm *lt=localtime(&t);
char temp[10];
size_t s = strftime(temp,10,preferences::clock_format().c_str(),lt);
if(s>0) {
return report(temp);
if (lt) {
char temp[10];
size_t s = strftime(temp,10,preferences::clock_format().c_str(),lt);
if(s>0) {
return report(temp);
} else {
return report();
}
} else {
return report();
}

View file

@ -94,8 +94,11 @@ std::string list_logdomains()
}
std::string get_timestamp(const time_t& t, const std::string& format) {
char buf[100];
strftime(buf, 100, format.c_str(), localtime(&t));
char buf[100] = {0};
tm* lt = localtime(&t);
if (lt) {
strftime(buf, 100, format.c_str(), lt);
}
return buf;
}