diff --git a/api/boinc_api.cpp b/api/boinc_api.cpp index a7597a3af7..c58111a182 100644 --- a/api/boinc_api.cpp +++ b/api/boinc_api.cpp @@ -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; } diff --git a/checkin_notes b/checkin_notes index bb7bdc1300..3d9df19d5c 100644 --- a/checkin_notes +++ b/checkin_notes @@ -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