From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by 2002:a05:6512:204:0:0:0:0 with SMTP id a4csp2926660lfo; Tue, 15 Mar 2022 07:43:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxEKL4l4QroO+5xU5aiyuCXuShaTvottQujXTxc0ZXf5vMAUjhEVTL2cACaizrQnG7NlKB3 X-Received: by 2002:a17:907:6283:b0:6db:aced:6698 with SMTP id nd3-20020a170907628300b006dbaced6698mr16464268ejc.283.1647355427298; Tue, 15 Mar 2022 07:43:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647355427; cv=none; d=google.com; s=arc-20160816; b=0ByhDdcXXEHlLF8/YklWKkJr3nZKElIEu7goiD8DOLbMKPBxVuf0jygBLW6c6QVDiA 9bYdQleFHsfUPwNJWy5sdKS4g3e28An0SLrCc8iDTbVFTMdMd+4U66FfqP7n6sZjvRdU iXZr4G3aaQrd1PwJ4oelB6b03CXfcx9ctqQ2zN7J0N/SWowUyvSvC7QWLE9ebVW2WlH3 fHg4ZNMqxFceDNsf+Y5fh+Z/Te1r9qok5dqOE4bhZ9M2JIQQcjExS96lwuTxOcMSL5Vl 2g5oRUuMNgBqk6egmZkTff5QbVuAI6BkkEOKZdxx3aOpBsax/bGaepWJ8m7gG0lIqVQm 9iQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from:dkim-signature; bh=H3Y1eIuJE5MHxgIwEc5Fk8JyYg2+dU4dKOkAeXX524I=; b=MJR/cmcvXkHbz0gWZSDjF1RKTtJnbKVk8tarno5E1wt/xXKgTBbblds7eQl26yedE2 toVL8QWhPkNc3zWCOiBAZafyaBOVe+1+0zuPeR+8l7N0jcpB3la96gVLOpD+AyRvNVvK j0ALqbaKZe3BFCxeWIO8PT3tCUPgg3jLvGycRvPDXTQ7LpLztaMFR5/CtoN0Y42SNC45 Q9T72eACjy0ccpRCWffKEBsOziFGOCSECyTpPYeQletVk9TU35rXNgIz2B/OIy4Cve6s TOEK0gRg/Hp9ByRjk2jgG9bIX77wpm0uFFTYqtWAEbVmOC7mhc1M04R1g9L+OIyAr5Go grVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VgJq8Z+e; spf=pass (google.com: domain of armbru@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=armbru@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com. [170.10.133.124]) by mx.google.com with ESMTPS id g4-20020a17090669c400b006cfea60027bsi10687671ejs.903.2022.03.15.07.43.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Mar 2022 07:43:47 -0700 (PDT) Received-SPF: pass (google.com: domain of armbru@redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VgJq8Z+e; spf=pass (google.com: domain of armbru@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=armbru@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647355426; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=H3Y1eIuJE5MHxgIwEc5Fk8JyYg2+dU4dKOkAeXX524I=; b=VgJq8Z+eT/dEvmPQmUnztxZInUh/pJlJy8Sg89lLrB+7HogMpRC7ecwqOT37t/i8vVN8Aw lvvrPWfUoQgtxZcm6gQVnJ1mD4rSjtUMKUlCqNwyfGztlUu+CFFNR7/GC2Uos8sRoucrBE gBoLna+B2VN8Mv1zfzT0eV2kkdYEgcI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-552-6t54DpkdO-mMtdvZzz0Pxg-1; Tue, 15 Mar 2022 10:43:45 -0400 X-MC-Unique: 6t54DpkdO-mMtdvZzz0Pxg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9DFC6811E76; Tue, 15 Mar 2022 14:43:42 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.36.112.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4A695555C90; Tue, 15 Mar 2022 14:43:42 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 417E921E66D4; Tue, 15 Mar 2022 15:43:41 +0100 (CET) From: Markus Armbruster To: Philippe =?utf-8?Q?Mathieu-Daud=C3=A9?= Cc: Alex =?utf-8?Q?Benn=C3=A9e?= , qemu-devel@nongnu.org, Paolo Bonzini , Richard Henderson , Gerd Hoffmann , Christian Schoenebeck , "Gonglei (Arei)" , =?utf-8?Q?Marc-Andr=C3=A9?= Lureau , "Michael S. Tsirkin" , Igor Mammedov , Ani Sinha , Laurent Vivier , Amit Shah , Peter Maydell , Stefano Stabellini , Anthony Perard , Paul Durrant , =?utf-8?Q?Herv=C3=A9?= Poussineau , Aleksandar Rikalo , Corey Minyard , Patrick Venture , Eduardo Habkost , Marcel Apfelbaum , Peter Xu , Jason Wang , =?utf-8?Q?C=C3=A9dric?= Le Goater , Daniel Henrique Barboza , David Gibson , Greg Kurz , Philippe =?utf-8?Q?Mathieu-Daud=C3=A9?= , Jean-Christophe Dubois , Keith Busch , Klaus Jensen , Yuval Shaia , Yoshinori Sato , Magnus Damm , Fabien Chouteau , KONRAD Frederic , Mark Cave-Ayland , Artyom Tarasenko , Alex Williamson , Eric Auger , Max Filippov , Juan Quintela , "Dr. David Alan Gilbert" , Konstantin Kostiuk , Michael Roth , Daniel P. =?utf-8?Q?Berrang=C3=A9?= , Pavel Dovgalyuk , David Hildenbrand , Wenchao Wang , Colin Xu , Kamil Rytarowski , Reinoud Zandijk , Sunil Muthuswamy , Cornelia Huck , Thomas Huth , Eric Blake , Vladimir Sementsov-Ogievskiy , John Snow , kvm@vger.kernel.org, qemu-arm@nongnu.org, xen-devel@lists.xenproject.org, qemu-ppc@nongnu.org, qemu-block@nongnu.org, haxm-team@intel.com, qemu-s390x@nongnu.org Subject: Re: [PATCH 3/3] Use g_new() & friends where that makes obvious sense References: <20220314160108.1440470-1-armbru@redhat.com> <20220314160108.1440470-4-armbru@redhat.com> <87y21c401e.fsf@linaro.org> <875yofl3k3.fsf@pond.sub.org> <02307072-4bff-dbbb-67fb-ca9800c34b3c@gmail.com> Date: Tue, 15 Mar 2022 15:43:41 +0100 In-Reply-To: <02307072-4bff-dbbb-67fb-ca9800c34b3c@gmail.com> ("Philippe =?utf-8?Q?Mathieu-Daud=C3=A9=22's?= message of "Tue, 15 Mar 2022 15:07:36 +0100") Message-ID: <875yofjmxu.fsf@pond.sub.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-TUID: hVpk/cQ0WBUI Philippe Mathieu-Daud=C3=A9 writes: > On 15/3/22 14:59, Markus Armbruster wrote: >> Alex Benn=C3=A9e writes: >>=20 >>> Markus Armbruster writes: >>> >>>> g_new(T, n) is neater than g_malloc(sizeof(T) * n). It's also safer, >>>> for two reasons. One, it catches multiplication overflowing size_t. >>>> Two, it returns T * rather than void *, which lets the compiler catch >>>> more type errors. >>>> >>> >>>> diff --git a/semihosting/config.c b/semihosting/config.c >>>> index 137171b717..6d48ec9566 100644 >>>> --- a/semihosting/config.c >>>> +++ b/semihosting/config.c >>>> @@ -98,7 +98,7 @@ static int add_semihosting_arg(void *opaque, >>>> if (strcmp(name, "arg") =3D=3D 0) { >>>> s->argc++; >>>> /* one extra element as g_strjoinv() expects NULL-terminated= array */ >>>> - s->argv =3D g_realloc(s->argv, (s->argc + 1) * sizeof(void *)= ); >>>> + s->argv =3D g_renew(void *, s->argv, s->argc + 1); >>> >>> This did indeed break CI because s->argv is an array of *char: >>> >>> ../semihosting/config.c:101:17: error: assignment to =E2=80=98const cha= r **=E2=80=99 from incompatible pointer type =E2=80=98void **=E2=80=99 [-We= rror=3Dincompatible-pointer-types] >>> 101 | s->argv =3D g_renew(void *, s->argv, s->argc + 1); >>> | ^ >>> cc1: all warnings being treated as errors >>> >>> So it did the job of type checking but failed to build ;-) >> >> You found a hole in my compile testing, thanks! >> >> I got confused about the configuration of my build trees. Catching such >> mistakes is what CI is for :) > > FYI Alex fixed this here: > https://lore.kernel.org/qemu-devel/20220315121251.2280317-8-alex.bennee@l= inaro.org/ > > So your series could go on top (modulo the Coverity change). I dropped this hunk in v2. Whether my v2 or Alex's series goes in first doesn't matter. 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 2325AC433F5 for ; Tue, 15 Mar 2022 14:55:03 +0000 (UTC) Received: from localhost ([::1]:59236 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nU8Zi-0001Gy-3t for qemu-devel@archiver.kernel.org; Tue, 15 Mar 2022 10:55:02 -0400 Received: from eggs.gnu.org ([209.51.188.92]:57812) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nU8Oq-0002fa-LQ for qemu-devel@nongnu.org; Tue, 15 Mar 2022 10:43:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:26956) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nU8Oo-0001g4-RX for qemu-devel@nongnu.org; Tue, 15 Mar 2022 10:43:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647355426; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=H3Y1eIuJE5MHxgIwEc5Fk8JyYg2+dU4dKOkAeXX524I=; b=VgJq8Z+eT/dEvmPQmUnztxZInUh/pJlJy8Sg89lLrB+7HogMpRC7ecwqOT37t/i8vVN8Aw lvvrPWfUoQgtxZcm6gQVnJ1mD4rSjtUMKUlCqNwyfGztlUu+CFFNR7/GC2Uos8sRoucrBE gBoLna+B2VN8Mv1zfzT0eV2kkdYEgcI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-552-6t54DpkdO-mMtdvZzz0Pxg-1; Tue, 15 Mar 2022 10:43:45 -0400 X-MC-Unique: 6t54DpkdO-mMtdvZzz0Pxg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9DFC6811E76; Tue, 15 Mar 2022 14:43:42 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.36.112.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4A695555C90; Tue, 15 Mar 2022 14:43:42 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 417E921E66D4; Tue, 15 Mar 2022 15:43:41 +0100 (CET) From: Markus Armbruster To: Philippe =?utf-8?Q?Mathieu-Daud=C3=A9?= Subject: Re: [PATCH 3/3] Use g_new() & friends where that makes obvious sense References: <20220314160108.1440470-1-armbru@redhat.com> <20220314160108.1440470-4-armbru@redhat.com> <87y21c401e.fsf@linaro.org> <875yofl3k3.fsf@pond.sub.org> <02307072-4bff-dbbb-67fb-ca9800c34b3c@gmail.com> Date: Tue, 15 Mar 2022 15:43:41 +0100 In-Reply-To: <02307072-4bff-dbbb-67fb-ca9800c34b3c@gmail.com> ("Philippe =?utf-8?Q?Mathieu-Daud=C3=A9=22's?= message of "Tue, 15 Mar 2022 15:07:36 +0100") Message-ID: <875yofjmxu.fsf@pond.sub.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Daniel Henrique Barboza , kvm@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , Christian Schoenebeck , qemu-devel@nongnu.org, Peter Xu , Klaus Jensen , KONRAD Frederic , Konstantin Kostiuk , Gerd Hoffmann , Ani Sinha , Reinoud Zandijk , Eric Blake , Sunil Muthuswamy , Stefano Stabellini , xen-devel@lists.xenproject.org, Yoshinori Sato , Juan Quintela , John Snow , Paul Durrant , Magnus Damm , Kamil Rytarowski , "Gonglei \(Arei\)" , =?utf-8?Q?Herv=C3=A9?= Poussineau , Michael Roth , Anthony Perard , =?utf-8?Q?Marc-Andr=C3=A9?= Lureau , Artyom Tarasenko , Laurent Vivier , Aleksandar Rikalo , Amit Shah , Mark Cave-Ayland , haxm-team@intel.com, Richard Henderson , Greg Kurz , Fabien Chouteau , Yuval Shaia , Thomas Huth , Eric Auger , Alex Williamson , qemu-arm@nongnu.org, =?utf-8?Q?C=C3=A9dric?= Le Goater , Pavel Dovgalyuk , Paolo Bonzini , Keith Busch , qemu-ppc@nongnu.org, David Hildenbrand , Alex =?utf-8?Q?Benn=C3=A9e?= , David Gibson , Eduardo Habkost , Vladimir Sementsov-Ogievskiy , "Daniel P. =?utf-8?Q?Berrang=C3=A9?=" , qemu-block@nongnu.org, Max Filippov , qemu-s390x@nongnu.org, Patrick Venture , Cornelia Huck , Philippe =?utf-8?Q?Mathieu-Daud=C3=A9?= , Jean-Christophe Dubois , Corey Minyard , Wenchao Wang , Igor Mammedov , "Dr. David Alan Gilbert" , Colin Xu Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Philippe Mathieu-Daud=C3=A9 writes: > On 15/3/22 14:59, Markus Armbruster wrote: >> Alex Benn=C3=A9e writes: >>=20 >>> Markus Armbruster writes: >>> >>>> g_new(T, n) is neater than g_malloc(sizeof(T) * n). It's also safer, >>>> for two reasons. One, it catches multiplication overflowing size_t. >>>> Two, it returns T * rather than void *, which lets the compiler catch >>>> more type errors. >>>> >>> >>>> diff --git a/semihosting/config.c b/semihosting/config.c >>>> index 137171b717..6d48ec9566 100644 >>>> --- a/semihosting/config.c >>>> +++ b/semihosting/config.c >>>> @@ -98,7 +98,7 @@ static int add_semihosting_arg(void *opaque, >>>> if (strcmp(name, "arg") =3D=3D 0) { >>>> s->argc++; >>>> /* one extra element as g_strjoinv() expects NULL-terminated= array */ >>>> - s->argv =3D g_realloc(s->argv, (s->argc + 1) * sizeof(void *)= ); >>>> + s->argv =3D g_renew(void *, s->argv, s->argc + 1); >>> >>> This did indeed break CI because s->argv is an array of *char: >>> >>> ../semihosting/config.c:101:17: error: assignment to =E2=80=98const cha= r **=E2=80=99 from incompatible pointer type =E2=80=98void **=E2=80=99 [-We= rror=3Dincompatible-pointer-types] >>> 101 | s->argv =3D g_renew(void *, s->argv, s->argc + 1); >>> | ^ >>> cc1: all warnings being treated as errors >>> >>> So it did the job of type checking but failed to build ;-) >> >> You found a hole in my compile testing, thanks! >> >> I got confused about the configuration of my build trees. Catching such >> mistakes is what CI is for :) > > FYI Alex fixed this here: > https://lore.kernel.org/qemu-devel/20220315121251.2280317-8-alex.bennee@l= inaro.org/ > > So your series could go on top (modulo the Coverity change). I dropped this hunk in v2. Whether my v2 or Alex's series goes in first doesn't matter.