From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4001:c0b::22a; helo=mail-it0-x22a.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-it0-x22a.google.com (mail-it0-x22a.google.com [IPv6:2607:f8b0:4001:c0b::22a]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 0A49D222CB33F for ; Tue, 26 Dec 2017 00:46:26 -0800 (PST) Received: by mail-it0-x22a.google.com with SMTP id t1so21804246ite.5 for ; Tue, 26 Dec 2017 00:51:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=eAHIZ5nCXV6iW/wW3JUXueVgPcDkLz2kPeWRh8Mubxo=; b=RnWJY7AcnGYsK8RfZN8z2AhmnPchBT7BkzbrlzAt6XByd6FteYFf0m/7gwgsVkeeKq VrVuv1w1d921xb69ysFzdMA/PwlLcIwhjQzp5OdT5ax0TzAhWBCRcF77TD9eOH0oeFNG X97YHrHBozfLAUDk7TmyI0LUcFppEAnuBHQfs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=eAHIZ5nCXV6iW/wW3JUXueVgPcDkLz2kPeWRh8Mubxo=; b=WOwhCYtu+ffI0pwebfqMU/GUmOSwFuPWIfVs9rmALmAu5OF1vMW7xlfUt/hTCBOlHS 8plTcY/RfbJvDucV9Mwqu5Hppdn0q0DeM7tM6PGLGR2FESao6yfAuQuHVfG4+ebsdjY4 R2GQPpDSPZ7zoNN7/92gEWKSyKbxSufFNGrM3Fga4q7iynCk6G4TvjcUJP+2Ls3lnD7F kDuBUGjKw3CPWkkPsocvsfWCAxBEAIU+//C2k6W+XdJul1684GOfbGyzeD2dXdJvZTUH CyyYVYXWWyFuc12AkmV6gOCF9bHUmJ9kTF9RfPfSd3Hce1pN3qkzZ8S7D+iVTR0mbiVV Pllw== X-Gm-Message-State: AKGB3mK8eCM1Hr5dBUwUALG6HjQAQXZggijdhylnhz6PqFPB4e/dC0wc ZpcpgEBTjvXMGIFBVURz7dwg93a3VXzh0t7E0ITvwGI7 X-Google-Smtp-Source: ACJfBotc7IKQbIwN4xxnY3ejYVBCFlHylEU9hNtu51+j0ydcQIoRaTtjkaitw3+sJCFnHOdduit6fDcBifLNZUN+Qao= X-Received: by 10.36.71.83 with SMTP id t80mr30362625itb.48.1514278280499; Tue, 26 Dec 2017 00:51:20 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.52.14 with HTTP; Tue, 26 Dec 2017 00:51:20 -0800 (PST) In-Reply-To: <4A89E2EF3DFEDB4C8BFDE51014F606A14E19885B@SHSMSX104.ccr.corp.intel.com> References: <1514277384-6480-1-git-send-email-liming.gao@intel.com> <4A89E2EF3DFEDB4C8BFDE51014F606A14E19885B@SHSMSX104.ccr.corp.intel.com> From: Ard Biesheuvel Date: Tue, 26 Dec 2017 08:51:20 +0000 Message-ID: To: "Gao, Liming" Cc: "edk2-devel@lists.01.org" , "Zeng, Star" Subject: Re: [Patch] MdeModulePkg Variable: Update Pointer Minus with UINTN type X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Dec 2017 08:46:27 -0000 Content-Type: text/plain; charset="UTF-8" On 26 December 2017 at 08:46, Gao, Liming wrote: > Ard: > Here is the simpler version. Convert pointer to UINTN, then subtract them to get the size, last convert it to UINT32. > > AuthVarStorage->Size = (UINT32)((UINTN) AuthStartPtr - (UINTN) AuthVarStorage); > That looks much better, thanks (although I prefer no space after the cast) >>-----Original Message----- >>From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org] >>Sent: Tuesday, December 26, 2017 4:39 PM >>To: Gao, Liming >>Cc: edk2-devel@lists.01.org; Zeng, Star >>Subject: Re: [edk2] [Patch] MdeModulePkg Variable: Update Pointer Minus >>with UINTN type >> >>On 26 December 2017 at 08:36, Liming Gao wrote: >>> Contributed-under: TianoCore Contribution Agreement 1.1 >>> Signed-off-by: Liming Gao >>> Cc: Star Zeng >> >>Could you please add an explanation why this is necessary? Do we >>really need 5 (!) casts to perform a simple subtraction? >> >>> --- >>> MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c | 2 +- >>> 1 file changed, 1 insertion(+), 1 deletion(-) >>> >>> diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c >>b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c >>> index 77905a0..a47270a 100644 >>> --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c >>> +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c >>> @@ -4125,7 +4125,7 @@ ConvertNormalVarStorageToAuthVarStorage ( >>> // >>> AuthVarStorage->Format = NormalVarStorage->Format; >>> AuthVarStorage->State = NormalVarStorage->State; >>> - AuthVarStorage->Size = (UINT32) (UINTN) ((UINT8 *) AuthStartPtr - >>(UINT8 *) AuthVarStorage); >>> + AuthVarStorage->Size = (UINT32)((UINTN) (UINT8 *) AuthStartPtr - >>(UINTN) (UINT8 *) AuthVarStorage); >>> CopyGuid (&AuthVarStorage->Signature, >>&gEfiAuthenticatedVariableGuid); >>> ASSERT (AuthVarStorage->Size <= AuthVarStroageSize); >>> >>> -- >>> 2.8.0.windows.1 >>> >>> _______________________________________________ >>> edk2-devel mailing list >>> edk2-devel@lists.01.org >>> https://lists.01.org/mailman/listinfo/edk2-devel