From 487de273455671edfd7a76d3c87bb5aaffd59ce1 Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Tue, 15 May 2018 18:56:36 -0700 Subject: [PATCH] Simplify code The static analyzer is concerned about the strcpys below this, since it apparently doesn't try to model snprintf's potential behaviors. (In particular, it was concerned that suffixLen might be >= sizeof(suffixBuf)). While that's clearly suboptimal, this code can also be simplified to make it more obvious what's happening and to appease the analyzer. No functionality change is intended. Bug: None Test: Ran the analyzer. It's no longer angry about strcpy overflows. Change-Id: I4aa812144c90f6d3e833bbcb23c0694476a0e53e --- liblog/logprint.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/liblog/logprint.c b/liblog/logprint.c index a2839bfb6..7937cb1c5 100644 --- a/liblog/logprint.c +++ b/liblog/logprint.c @@ -1632,8 +1632,10 @@ LIBLOG_ABI_PUBLIC char* android_log_formatLogLine(AndroidLogFormat* p_format, prefixLen = snprintf(prefixBuf, sizeof(prefixBuf), "\x1B[38;5;%dm", colorFromPri(entry->priority)); prefixLen = MIN(prefixLen, sizeof(prefixBuf)); - suffixLen = snprintf(suffixBuf, sizeof(suffixBuf), "\x1B[0m"); - suffixLen = MIN(suffixLen, sizeof(suffixBuf)); + + const char suffixContents[] = "\x1B[0m"; + strcpy(suffixBuf, suffixContents); + suffixLen = strlen(suffixContents); } char uid[16];