From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id AE0BD8219F for ; Sun, 26 Feb 2017 21:07:48 -0800 (PST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Feb 2017 21:07:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,212,1484035200"; d="scan'208";a="828767187" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by FMSMGA003.fm.intel.com with ESMTP; 26 Feb 2017 21:07:47 -0800 Received: from fmsmsx101.amr.corp.intel.com (10.18.124.199) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.248.2; Sun, 26 Feb 2017 21:07:47 -0800 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by fmsmsx101.amr.corp.intel.com (10.18.124.199) with Microsoft SMTP Server (TLS) id 14.3.248.2; Sun, 26 Feb 2017 21:07:47 -0800 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.59]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.132]) with mapi id 14.03.0248.002; Mon, 27 Feb 2017 13:07:45 +0800 From: "Ni, Ruiyu" To: "Wu, Hao A" , "edk2-devel@lists.01.org" CC: "Wu, Hao A" Thread-Topic: [edk2] [PATCH v3 03/12] FatPkg: Refine casting expression result to bigger size Thread-Index: AQHSjyXWfjzJQzhh902iAJc/7in7FqF8UExg Date: Mon, 27 Feb 2017 05:07:44 +0000 Deferred-Delivery: Mon, 27 Feb 2017 05:07:00 +0000 Message-ID: <734D49CCEBEEF84792F5B80ED585239D5B8B47DE@SHSMSX104.ccr.corp.intel.com> References: <1487999555-9764-1-git-send-email-hao.a.wu@intel.com> <1487999555-9764-4-git-send-email-hao.a.wu@intel.com> In-Reply-To: <1487999555-9764-4-git-send-email-hao.a.wu@intel.com> Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH v3 03/12] FatPkg: Refine casting expression result to bigger size X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Feb 2017 05:07:48 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Ruiyu Ni Thanks/Ray > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of > Hao Wu > Sent: Saturday, February 25, 2017 1:12 PM > To: edk2-devel@lists.01.org > Cc: Wu, Hao A ; Ni, Ruiyu > Subject: [edk2] [PATCH v3 03/12] FatPkg: Refine casting expression result= to > bigger size >=20 > There are cases that the operands of an expression are all with rank less= than > UINT64/INT64 and the result of the expression is explicitly cast to > UINT64/INT64 to fit the target size. >=20 > An example will be: > UINT32 a,b; > // a and b can be any unsigned int type with rank less than UINT64, like = // > UINT8, UINT16, etc. > UINT64 c; > c =3D (UINT64) (a + b); >=20 > Some static code checkers may warn that the expression result might > overflow within the rank of "int" (integer promotions) and the result is = then > cast to a bigger size. >=20 > The commit refines codes by the following rules: > 1). When the expression is possible to overflow the range of unsigned int= / > int: > c =3D (UINT64)a + b; >=20 > 2). When the expression will not overflow within the rank of "int", remov= e > the explicit type casts: > c =3D a + b; >=20 > 3). When the expression will be cast to pointer of possible greater size: > UINT32 a,b; > VOID *c; > c =3D (VOID *)(UINTN)(a + b); --> c =3D (VOID *)((UINTN)a + b); >=20 > 4). When one side of a comparison expression contains only operands with > rank less than UINT32: > UINT8 a; > UINT16 b; > UINTN c; > if ((UINTN)(a + b) > c) {...} --> if (((UINT32)a + b) > c) {...} >=20 > For rule 4), if we remove the 'UINTN' type cast like: > if (a + b > c) {...} > The VS compiler will complain with warning C4018 (signed/unsigned > mismatch, level 3 warning) due to promoting 'a + b' to type 'int'. >=20 > Cc: Ruiyu Ni > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Hao Wu > --- > FatPkg/EnhancedFatDxe/ReadWrite.c | 4 ++-- > FatPkg/FatPei/FatLiteAccess.c | 4 ++-- > 2 files changed, 4 insertions(+), 4 deletions(-) >=20 > diff --git a/FatPkg/EnhancedFatDxe/ReadWrite.c > b/FatPkg/EnhancedFatDxe/ReadWrite.c > index a6e0ec4..ad3c260 100644 > --- a/FatPkg/EnhancedFatDxe/ReadWrite.c > +++ b/FatPkg/EnhancedFatDxe/ReadWrite.c > @@ -1,7 +1,7 @@ > /** @file > Functions that perform file read/write. >=20 > -Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved.
> +Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.
> This program and the accompanying materials are licensed and made > available under the terms and conditions of the BSD License which > accompanies this distribution. The full text of the license may be found= at > @@ -173,7 +173,7 @@ Done: > // Update IFile->Position, if everything is all right > // > CurrentPos =3D ODir->CurrentPos; > - IFile->Position =3D (UINT64) (CurrentPos * sizeof (FAT_DIRECTORY_ENT= RY)); > + IFile->Position =3D CurrentPos * sizeof (FAT_DIRECTORY_ENTRY); > } >=20 > return Status; > diff --git a/FatPkg/FatPei/FatLiteAccess.c b/FatPkg/FatPei/FatLiteAccess.= c > index 1106345..a92c5bf 100644 > --- a/FatPkg/FatPei/FatLiteAccess.c > +++ b/FatPkg/FatPei/FatLiteAccess.c > @@ -1,7 +1,7 @@ > /** @file > FAT file system access routines for FAT recovery PEIM >=20 > -Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.
> +Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
>=20 > This program and the accompanying materials are licensed and made > available under the terms and conditions of the BSD License which > accompanies this @@ -393,7 +393,7 @@ FatReadFile ( > } else { >=20 > if ((File->Attributes & FAT_ATTR_DIRECTORY) =3D=3D 0) { > - Size =3D Size < (File->FileSize - File->CurrentPos) ? Size : (UINT= N) (File- > >FileSize - File->CurrentPos); > + Size =3D Size < (File->FileSize - File->CurrentPos) ? Size : > + (File->FileSize - File->CurrentPos); > } > // > // This is a normal cluster based file > -- > 1.9.5.msysgit.0 >=20 > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel