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.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 93610C433EF for ; Tue, 15 Mar 2022 14:44:02 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.290861.493435 (Exim 4.92) (envelope-from ) id 1nU8Ot-0001Dp-Fu; Tue, 15 Mar 2022 14:43:51 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 290861.493435; Tue, 15 Mar 2022 14:43:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nU8Ot-0001Di-D2; Tue, 15 Mar 2022 14:43:51 +0000 Received: by outflank-mailman (input) for mailman id 290861; Tue, 15 Mar 2022 14:43:50 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nU8Os-0001DW-AR for xen-devel@lists.xenproject.org; Tue, 15 Mar 2022 14:43:50 +0000 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 52cc8dea-a46e-11ec-853b-5f4723681683; Tue, 15 Mar 2022 15:43:49 +0100 (CET) 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 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) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 52cc8dea-a46e-11ec-853b-5f4723681683 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647355428; 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=S548N/LDeQqTJ6yJISHbwJWzNRUEks7RQqM0SHpT+623Z7e4o6j0MHT/qzub1X/hvSR/pT wPv89Gf5vhQyCGtMb7n5TT1x8WxVNOeZMVKESOTX+vCl3hovuAHQxLxv30amuRbJM+Ks1E nOIFSMEj/0fVtU5YTY5B8nsJmZevnt8= X-MC-Unique: 6t54DpkdO-mMtdvZzz0Pxg-1 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 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.