From patchwork Wed Jun 28 12:04:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 9814069 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 07C8B603D7 for ; Wed, 28 Jun 2017 12:04:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED1452823D for ; Wed, 28 Jun 2017 12:04:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E0BF428521; Wed, 28 Jun 2017 12:04:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 85C642823D for ; Wed, 28 Jun 2017 12:04:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751512AbdF1ME1 (ORCPT ); Wed, 28 Jun 2017 08:04:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60642 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751489AbdF1MEZ (ORCPT ); Wed, 28 Jun 2017 08:04:25 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6D2637EBDE for ; Wed, 28 Jun 2017 12:04:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6D2637EBDE Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=thuth@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6D2637EBDE Received: from thh440s.redhat.com (ovpn-116-134.ams2.redhat.com [10.36.116.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 813A9955B4; Wed, 28 Jun 2017 12:04:18 +0000 (UTC) From: Thomas Huth To: kvm@vger.kernel.org Cc: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Drew Jones , David Hildenbrand Subject: [kvm-unit-tests PATCH] Compile code with "-Wwrite-strings" Date: Wed, 28 Jun 2017 14:04:17 +0200 Message-Id: <1498651457-19688-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 28 Jun 2017 12:04:25 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP So we make sure that we do not accidentially write to constant strings. Also add some missing "const" qualifiers in the code to avoid that we get compiler warnings now. Signed-off-by: Thomas Huth Reviewed-by: David Hildenbrand --- This patch supersedes my previous patch "Declare the prefix string variable in va_report() as const" Makefile | 2 +- lib/report.c | 6 +++--- x86/msr.c | 4 ++-- x86/pmu.c | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 933b9f0..e79cf93 100644 --- a/Makefile +++ b/Makefile @@ -51,7 +51,7 @@ cc-option = $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null \ > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;) CFLAGS += -g -CFLAGS += $(autodepend-flags) -Wall -Werror +CFLAGS += $(autodepend-flags) -Wall -Wwrite-strings -Werror frame-pointer-flag=-f$(if $(KEEP_FRAME_POINTER),no-,)omit-frame-pointer fomit_frame_pointer := $(call cc-option, $(frame-pointer-flag), "") fnostack_protector := $(call cc-option, -fno-stack-protector, "") diff --git a/lib/report.c b/lib/report.c index b002d21..5da27ab 100644 --- a/lib/report.c +++ b/lib/report.c @@ -81,9 +81,9 @@ void report_prefix_pop(void) static void va_report(const char *msg_fmt, bool pass, bool xfail, bool skip, va_list va) { - char *prefix = skip ? "SKIP" - : xfail ? (pass ? "XPASS" : "XFAIL") - : (pass ? "PASS" : "FAIL"); + const char *prefix = skip ? "SKIP" + : xfail ? (pass ? "XPASS" : "XFAIL") + : (pass ? "PASS" : "FAIL"); spin_lock(&lock); diff --git a/x86/msr.c b/x86/msr.c index 91351a3..ffc24b1 100644 --- a/x86/msr.c +++ b/x86/msr.c @@ -6,7 +6,7 @@ struct msr_info { int index; - char *name; + const char *name; struct tc { int valid; unsigned long long value; @@ -78,7 +78,7 @@ static void test_msr_rw(int msr_index, unsigned long long input, unsigned long l { unsigned long long r = 0; int index; - char *sptr; + const char *sptr; if ((index = find_msr_info(msr_index)) != -1) { sptr = msr_info[index].name; } else { diff --git a/x86/pmu.c b/x86/pmu.c index c689800..a0238dc 100644 --- a/x86/pmu.c +++ b/x86/pmu.c @@ -73,7 +73,7 @@ union cpuid10_edx { } edx; struct pmu_event { - char *name; + const char *name; uint32_t unit_sel; int min; int max;