- api: check return values of functions used in boinc_msg_prefix(),

return a (valid) empty string if an error occurred

svn path=/trunk/boinc/; revision=22781
This commit is contained in:
Bernd Machenschalk 2010-12-01 15:25:07 +00:00
parent 16147b7dd7
commit 0220ab3319
2 changed files with 32 additions and 6 deletions

View File

@ -195,16 +195,35 @@ static int start_worker_signals();
char* boinc_msg_prefix(char* sbuf, int len) {
char buf[256];
struct tm* tm;
time_t x = time(0);
struct tm* tm = localtime(&x);
strftime(buf, sizeof(buf)-1, "%H:%M:%S", tm);
if(x == (time_t)-1) {
*sbuf='\0'; // make sure there is a valid (empty) string returned
return sbuf;
}
if(!(tm = localtime(&x))) {
*sbuf='\0'; // make sure there is a valid (empty) string returned
return sbuf;
}
if(!strftime(buf, sizeof(buf)-1, "%H:%M:%S", tm)) {
*sbuf='\0'; // make sure there is a valid (empty) string returned
return sbuf;
}
#ifdef _WIN32
_snprintf(sbuf, len, "%s (%d):", buf, GetCurrentProcessId());
if(_snprintf(sbuf, len, "%s (%d):", buf, GetCurrentProcessId()) < 0)
#else
snprintf(sbuf, len, "%s (%d):", buf, getpid());
if(snprintf(sbuf, len, "%s (%d):", buf, getpid()) < 0)
#endif
sbuf[len-1] = 0; // just in case
{
*sbuf='\0'; // make sure there is a valid (empty) string returned
return sbuf;
}
sbuf[len-1] = '\0'; // just in case
return sbuf;
}

View File

@ -8518,3 +8518,10 @@ David 30 Nov 2010
client/
client_state.cpp
cpu_sched.cpp
Bernd 01 Dec 2010
- api: check return values of functions used in boinc_msg_prefix(),
return a (valid) empty string if an error occurred
api/
boinc-api.cpp