From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2C57CA9EA5 for ; Fri, 18 Oct 2019 11:01:38 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C87752064B for ; Fri, 18 Oct 2019 11:01:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C87752064B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:37958 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iLQ0n-0004ae-JK for qemu-devel@archiver.kernel.org; Fri, 18 Oct 2019 07:01:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58084) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iLPwc-0008HJ-01 for qemu-devel@nongnu.org; Fri, 18 Oct 2019 06:57:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iLPwa-0002cv-ON for qemu-devel@nongnu.org; Fri, 18 Oct 2019 06:57:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42546) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iLPwa-0002cl-46; Fri, 18 Oct 2019 06:57:16 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5C581308A9E2; Fri, 18 Oct 2019 10:57:15 +0000 (UTC) Received: from redhat.com (ovpn-112-62.ams2.redhat.com [10.36.112.62]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 99A6D1001B05; Fri, 18 Oct 2019 10:57:13 +0000 (UTC) Date: Fri, 18 Oct 2019 11:57:10 +0100 From: Daniel =?utf-8?B?UC4gQmVycmFuZ8Op?= To: Thomas Huth Subject: Re: [PATCH] Do not use %m in common code to print error messages Message-ID: <20191018105710.GD28271@redhat.com> References: <20191018104438.6158-1-thuth@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20191018104438.6158-1-thuth@redhat.com> User-Agent: Mutt/1.12.1 (2019-06-15) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 18 Oct 2019 10:57:15 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Daniel =?utf-8?B?UC4gQmVycmFuZ8Op?= Cc: qemu-trivial@nongnu.org, Paolo Bonzini , Kamil Rytarowski , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On Fri, Oct 18, 2019 at 12:44:38PM +0200, Thomas Huth wrote: > The %m format specifier is an extension from glibc - and when compiling > QEMU for NetBSD, the compiler correctly complains, e.g.: > > /home/qemu/qemu-test.ELjfrQ/src/util/main-loop.c: In function 'sigfd_handler': > /home/qemu/qemu-test.ELjfrQ/src/util/main-loop.c:64:13: warning: %m is only > allowed in syslog(3) like functions [-Wformat=] > printf("read from sigfd returned %zd: %m\n", len); > ^ > Let's use g_strerror() here instead, which is an easy-to-use wrapper > around the thread-safe strerror_r() function. > > While we're at it, also convert the "printf()" in main-loop.c into > the preferred "error_report()". > > Signed-off-by: Thomas Huth > --- > hw/misc/tmp421.c | 8 ++++++-- > util/main-loop.c | 4 +++- > util/systemd.c | 5 +++-- > 3 files changed, 12 insertions(+), 5 deletions(-) > > diff --git a/hw/misc/tmp421.c b/hw/misc/tmp421.c > index 9f044705fa..f23c46a40a 100644 > --- a/hw/misc/tmp421.c > +++ b/hw/misc/tmp421.c > @@ -120,7 +120,9 @@ static void tmp421_get_temperature(Object *obj, Visitor *v, const char *name, > int tempid; > > if (sscanf(name, "temperature%d", &tempid) != 1) { > - error_setg(errp, "error reading %s: %m", name); > + const char *errmsg = g_strerror(errno); > + error_setg(errp, "error reading %s: %s", name, errmsg); > + g_free((gpointer)errmsg); Kaboom crash. This is trying to free a const string that is the caller doesn't own. It remains under ownership of g_strerror forever. Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|