From cf6cbfb7f759b45a2388919492b42b016736f818 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Sat, 2 Nov 2024 21:54:27 +0100 Subject: [PATCH] tests: check strftime result --- test/lib/brick-shelltest.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/test/lib/brick-shelltest.h b/test/lib/brick-shelltest.h index 4c70f543a..afd1fc9a4 100644 --- a/test/lib/brick-shelltest.h +++ b/test/lib/brick-shelltest.h @@ -322,8 +322,8 @@ struct Journal { char buf[64]; time_t t = time( 0 ); if (localtime_r(&t, &time_info)) { - strftime(buf, sizeof(buf), "%F %T", &time_info); - of << "--- " << buf << " ---"; + if ( strftime( buf, sizeof(buf), "%F %T", &time_info ) ) + of << "--- " << buf << " ---"; } } of << std::endl; @@ -716,7 +716,7 @@ struct KMsg : Source { unsigned level, num, pos; unsigned long t; time_t tt; - size_t len; + size_t len, slen; const char *delimiter; buf[ *sz ] = 0; @@ -728,8 +728,10 @@ struct KMsg : Source { memcpy( newbuf, buf, *sz ); tt = time( 0 ); len = snprintf( buf, 64, "[%lu.%06lu] <%u> ", t / 1000000, t % 1000000, level ); - if ( localtime_r( &tt, &time_info ) ) - len += strftime( buf + len, 64, "%F %T ", &time_info ); + if ( localtime_r( &tt, &time_info ) && + ( slen = strftime( buf + len, 64, "%F %T ", &time_info ) ) ) + len += slen; + memcpy( buf + len, newbuf + pos, *sz - pos ); *sz = *sz - pos + len; }