tools:acrn-crashlog: Enhance some functions

The changes include:

1. modify the outparam only in successful cases.
2. return -1 instead of  a errno-style value if error happens.
3. check return value of strrchr.

Tracked-On: #971
Signed-off-by: Liu, Xinwu <xinwu.liu@intel.com>
Acked-by: Chen Gang <gang.c.chen@intel.com>
This commit is contained in:
Liu, Xinwu
2018-08-01 15:29:51 +08:00
committed by lijinxia
parent 10f0bb012a
commit 5e32c0227f
4 changed files with 63 additions and 44 deletions

View File

@@ -17,9 +17,7 @@ void do_log(const int level,
va_list args;
char *fmt;
char log[MAX_LOG_LEN];
char *msg_log;
int n = 0;
int msg_len = 0;
#ifdef DEBUG_ACRN_CRASHLOG
const char header_fmt[] = "<%-20s%5d>: ";
#endif
@@ -42,10 +40,8 @@ void do_log(const int level,
if (n < 0 || (size_t)n >= sizeof(log))
n = 0;
#endif
msg_log = log + n;
msg_len = sizeof(log) - n;
/* msg */
vsnprintf(msg_log, msg_len, fmt, args);
vsnprintf(log + n, sizeof(log) - (size_t)n, fmt, args);
log[sizeof(log) - 1] = 0;
va_end(args);