From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by mx.groups.io with SMTP id smtpd.web12.21624.1595432128634195967 for ; Wed, 22 Jul 2020 08:35:28 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@nuviainc-com.20150623.gappssmtp.com header.s=20150623 header.b=lrb0N5nY; spf=pass (domain: nuviainc.com, ip: 209.85.221.66, mailfrom: leif@nuviainc.com) Received: by mail-wr1-f66.google.com with SMTP id z15so2329022wrl.8 for ; Wed, 22 Jul 2020 08:35:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nuviainc-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=MmI4XEGP8pNa/ESs39vDmZ9JFDTJpwTLo7fHrJZE24w=; b=lrb0N5nYUo5f6idnb4B+tkU1flF5v2h36uHWC/2sNKqQ+sDessm73AihyQnu9JzpyK 6OE4VKJbaJHgRFgMnZZCFNTflxnYk6FgPCABGzUFKf47RRF6mOrt0YZHUo5JUbqDY8xA yY8sh/zo1h5/0Ltiif8Lj8cc7JsMgC8HiJRsCnDBn4JcRkeePCrQUBathcBaT39MFscH So6/9l/Uu9ifdG68CTAkFnjSc6Xo3dA4+bKGUDmED9eqRvbKV9xEpHv2BQGwoaf4yQPt fARM1sO8/HXvj09k5OXvOJy0+B9xSPr2eg3V0z4+JQAtOoBe3fSquANNSc8fxsJw2UcM 0+HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=MmI4XEGP8pNa/ESs39vDmZ9JFDTJpwTLo7fHrJZE24w=; b=oRu98HzDwxJuMdzk3AICeAaIABDsC+d3Bculen8OUZcI50KBadbSWnMTLwg4mHWl9J ZgwFIC07cQLyavM+nqR35IjzkuA1jx8wLXYW9aAmkDrZoxfi8/x13LdTchrNygEtKV5D /X8M/6IIzaiWogdMUxd+lAIGVdeeKYUp3WBIO+KtZUWpZpYsNk+AOVejI3ArzaerzloG Cukz6CiaVflSqGHa++kUL3Oh99/MBdQTu2T/TOtDuF4RZfg2E9tdGLKfc8pXhq/ieX8G U2MgSp6dTDCOeRsl+PWw5ky58uHKWdHUXNZbkXYITLamLCjXJ6vih2ENyILb6hH8mCQ+ xcdw== X-Gm-Message-State: AOAM531MCnRqxxTM+ZxaiXy2Qe8qqQ57/rSaLhDcRQNlE62gU9PAVke3 CzO3UXSh0f4Hc0mQW1cO71ADWA== X-Google-Smtp-Source: ABdhPJxkOG8+Otr0UG4ecXZpMsT3CnC1V+8vV1ClEwG+SpRGyzAQEicvA11rxAwbS6xOu3wi+ifw0g== X-Received: by 2002:a05:6000:c:: with SMTP id h12mr125627wrx.49.1595432127062; Wed, 22 Jul 2020 08:35:27 -0700 (PDT) Return-Path: Received: from vanye ([2001:470:1f09:12f0:b26e:bfff:fea9:f1b8]) by smtp.gmail.com with ESMTPSA id k20sm80839wmi.27.2020.07.22.08.35.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2020 08:35:26 -0700 (PDT) Date: Wed, 22 Jul 2020 16:35:24 +0100 From: "Leif Lindholm" To: PierreGondois Cc: devel@edk2.groups.io, ard.biesheuvel@arm.com, nd@arm.com, lersek@redhat.com Subject: Re: [PATCH v1 2/2] EmbeddedPkg: Add cast from (void*) for VS2017 build Message-ID: <20200722153524.GE1337@vanye> References: <20200630104901.11648-1-pierre.gondois@arm.com> <20200630104901.11648-3-pierre.gondois@arm.com> MIME-Version: 1.0 In-Reply-To: <20200630104901.11648-3-pierre.gondois@arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Jun 30, 2020 at 11:49:01 +0100, PierreGondois wrote: > From: Pierre Gondois > > The following build configrations: > build -b DEBUG -a AARCH64 -t VS2017 -p edk2\EmbeddedPkg\EmbeddedPkg.dsc > build -b NOOPT -a AARCH64 -t VS2017 -p edk2\EmbeddedPkg\EmbeddedPkg.dsc > build -b RELEASE -a AARCH64 -t VS2017 -p edk2\EmbeddedPkg\EmbeddedPkg.dsc > > are generating the following build errors: > edk2\EmbeddedPkg\Library\AndroidBootImgLib\AndroidBootImgLib.c(100): > error C2036: 'void *': unknown size > edk2\EmbeddedPkg\Library\AndroidBootImgLib\AndroidBootImgLib.c(347): > error C2036: 'void *': unknown size > > Since the size of void* depends on the architecture, it can be > dangerous to use void* pointer arithmetic. Plus the C99 doesn't state > that void* pointer arithmetic is allowed. > This patch adds a cast to fix the Visual Studio errors reported. > > Signed-off-by: Pierre Gondois > --- > > The changes can be seen at: https://github.com/PierreARM/edk2/commits/831_Fix_VS2017_build_error_v1 > > Notes: > v1: > - Fix VS2017 build errors. [Pierre] > > EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c | 13 ++++++++----- > 1 file changed, 8 insertions(+), 5 deletions(-) > > diff --git a/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c b/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c > index e1036954ee586dfc30266eec2897d71bfc949038..bbe0d41018b3d5665c72ee61efe737ae57b1b2eb 100644 > --- a/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c > +++ b/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c > @@ -1,6 +1,6 @@ > /** @file > > - Copyright (c) 2013-2014, ARM Ltd. All rights reserved.
> + Copyright (c) 2013-2020, ARM Ltd. All rights reserved.
> Copyright (c) 2017, Linaro. All rights reserved. > > SPDX-License-Identifier: BSD-2-Clause-Patent > @@ -97,7 +97,7 @@ AndroidBootImgGetKernelInfo ( > ASSERT (IS_VALID_ANDROID_PAGE_SIZE (Header->PageSize)); > > *KernelSize = Header->KernelSize; > - *Kernel = BootImg + Header->PageSize; > + *Kernel = (UINT8*)BootImg + Header->PageSize; The reason I prefer my version, although this one would also solve the compilation error, is that I really don't like casts to char * (which this effectively is) as a workaround. The problem I have with it is that a cast is a signal of intent (this thing that we have been viewing as an X should now be seen as a Y) - and the intent here is simply to get the side effect that a char has a known size of 1 (whereas a void doesn't). I will admit it is the first time I have seen it used for this purpose :) The same problem occure when casting to char * in order to not have to deal with pointer arithmetic at all or to avoid thinking about alignment requirements. And both of these are frequently indicators of buggy code. / Leif > return EFI_SUCCESS; > } > > @@ -339,9 +339,12 @@ AndroidBootImgUpdateFdt ( > goto Fdt_Exit; > } > > - Status = AndroidBootImgSetProperty64 (UpdatedFdtBase, ChosenNode, > - "linux,initrd-end", > - (UINTN)(RamdiskData + RamdiskSize)); > + Status = AndroidBootImgSetProperty64 ( > + UpdatedFdtBase, > + ChosenNode, > + "linux,initrd-end", > + (UINTN)((UINT8*)RamdiskData + RamdiskSize) > + ); > if (EFI_ERROR (Status)) { > goto Fdt_Exit; > } > -- > 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)' >