From patchwork Fri May 15 10:36:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Ian King X-Patchwork-Id: 472714 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id D7EAF14016A; Fri, 15 May 2015 20:38:25 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1YtD0a-0002oM-PA; Fri, 15 May 2015 10:38:24 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1YtD0W-0002oH-0A for fwts-devel@lists.ubuntu.com; Fri, 15 May 2015 10:38:20 +0000 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1YtD0V-0002qd-Rf for fwts-devel@lists.ubuntu.com; Fri, 15 May 2015 10:38:19 +0000 From: Colin King To: fwts-devel@lists.ubuntu.com Subject: [PATCH] lib: acpica: explicitly set buffer to NULL to remove cppcheck warning Date: Fri, 15 May 2015 11:36:24 +0100 Message-Id: <1431686184-12609-1-git-send-email-colin.king@canonical.com> X-Mailer: git-send-email 2.1.4 X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: fwts-devel-bounces@lists.ubuntu.com From: Colin Ian King cppcheck isn't quite so smart as CoverityScan so it continues to complain about a potential free issue as a false positive. I've taken the liberty to explicity set buffer to NULL to make the code clearer and this helps cppcheck to understand the flow of control better. Signed-off-by: Colin Ian King Acked-by: Alex Hung Acked-by: Ivan Hu --- src/acpica/fwts_acpica.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/acpica/fwts_acpica.c b/src/acpica/fwts_acpica.c index 4a6baf6..9bfd0ae 100644 --- a/src/acpica/fwts_acpica.c +++ b/src/acpica/fwts_acpica.c @@ -452,8 +452,10 @@ void fwts_acpica_vprintf(const char *fmt, va_list args) buffer = malloc(buffer_len); if (buffer) strcpy(buffer, tmp); - else + else { + buffer = NULL; buffer_len = 0; + } } else { char *new_buf; @@ -464,11 +466,12 @@ void fwts_acpica_vprintf(const char *fmt, va_list args) strcat(buffer, tmp); } else { free(buffer); + buffer = NULL; buffer_len = 0; } } - if (buffer_len && index(buffer, '\n') != NULL) { + if (buffer && index(buffer, '\n') != NULL) { fwts_log_info(fwts_acpica_fw, "%s", buffer); free(buffer); buffer_len = 0;