Return-Path: Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id b2-20020a17090630c200b006d58f94acecsm8336788ejb.210.2022.03.15.09.17.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Mar 2022 09:17:29 -0700 (PDT) Received: from zen (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id DA6F31FFB7; Tue, 15 Mar 2022 16:17:28 +0000 (GMT) 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> <875yofjmxu.fsf@pond.sub.org> User-agent: mu4e 1.7.10; emacs 28.0.92 From: Alex =?utf-8?Q?Benn=C3=A9e?= To: Markus Armbruster Cc: Philippe =?utf-8?Q?Mathieu-Daud=C3=A9?= , 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 , =?utf-8?Q?Daniel_P=2E_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 Date: Tue, 15 Mar 2022 16:16:54 +0000 In-reply-to: <875yofjmxu.fsf@pond.sub.org> Message-ID: <875yof42cn.fsf@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-TUID: qwkL6t0nA3wI Markus Armbruster writes: > 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-terminate= d 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 ch= ar **=E2=80=99 from incompatible pointer type =E2=80=98void **=E2=80=99 [-W= error=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@= linaro.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. That's great. Thanks for finding the ugliness in the first place ;-) --=20 Alex Benn=C3=A9e