summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Burgess IV2018-05-15 20:56:36 -0500
committerGeorge Burgess IV2018-05-15 22:06:59 -0500
commit487de273455671edfd7a76d3c87bb5aaffd59ce1 (patch)
treea7761a23e2a70a824d4a48af19061d5810fe090f
parent48cf760bea211b43aa79675c6b73f846202865f9 (diff)
downloadplatform-system-core-487de273455671edfd7a76d3c87bb5aaffd59ce1.tar.gz
platform-system-core-487de273455671edfd7a76d3c87bb5aaffd59ce1.tar.xz
platform-system-core-487de273455671edfd7a76d3c87bb5aaffd59ce1.zip
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
-rw-r--r--liblog/logprint.c6
1 files 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,
1632 prefixLen = snprintf(prefixBuf, sizeof(prefixBuf), "\x1B[38;5;%dm", 1632 prefixLen = snprintf(prefixBuf, sizeof(prefixBuf), "\x1B[38;5;%dm",
1633 colorFromPri(entry->priority)); 1633 colorFromPri(entry->priority));
1634 prefixLen = MIN(prefixLen, sizeof(prefixBuf)); 1634 prefixLen = MIN(prefixLen, sizeof(prefixBuf));
1635 suffixLen = snprintf(suffixBuf, sizeof(suffixBuf), "\x1B[0m"); 1635
1636 suffixLen = MIN(suffixLen, sizeof(suffixBuf)); 1636 const char suffixContents[] = "\x1B[0m";
1637 strcpy(suffixBuf, suffixContents);
1638 suffixLen = strlen(suffixContents);
1637 } 1639 }
1638 1640
1639 char uid[16]; 1641 char uid[16];