]> git.proxmox.com Git - mirror_edk2.git/commitdiff
StdLib: The formatting for double float values, within the gdtoa library, is improper.
authorDaryl McDaniel <daryl.mcdaniel@intel.com>
Wed, 6 Aug 2014 18:29:02 +0000 (18:29 +0000)
committerdarylm503 <darylm503@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 6 Aug 2014 18:29:02 +0000 (18:29 +0000)
When running Enquire.efi, several errors similar to the following are produced:
Maximum exponent = 128
Maximum number = 3.40282347e+38

*** WARNING: Possibly bad output from printf above
    expected value around 3.40282347e38, bit pattern:
    11111111 11111111 01111111 01111111
    sscanf gave           -inf, bit pattern:
    00000000 00000000 10000000 11111111
    difference= inf

Overflow doesn’t seem to generate a trap

The memory allocation tests will also fail, sometimes leaving all available memory consumed.

The correct output in the above example is:
Maximum exponent = 128
Maximum number = 3.40282347e+38
Overflow doesn't seem to generate a trap

The root cause is that all operations on values of Long or ULong type, within the gdtoa library, must be 32-bit operations.  A previous change replaced the Long and ULong definitions with INTN and UINTN, respectively.  While this is correct for a lot of Linux and NetBSD code, it was not correct for this library.

This fix reverts the definitions of ULong and Long back to 32-bit types.
A descriptive comment has also been added to the U union.
Additional white-space has been added to tidy up the definitions of the word0 and word1 macros.

Verified with Enquire.efi and the ISO/IEC C Library compliance Validation Suite.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Daryl McDaniel <daryl.mcdaniel@intel.com>
Reviewed-by: Jaben Carsey <Jaben.carsey@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15765 6f19259b-4bc3-4df7-8a09-765794883524

StdLib/LibC/gdtoa/gdtoa.h
StdLib/LibC/gdtoa/gdtoaimp.h

index 82f126caf2462e256be52c536e380927eae99ffe..8617a57409108dcc3f9ca9637fe5b18be2a92f0b 100644 (file)
@@ -1,6 +1,13 @@
-/* $NetBSD: gdtoa.h,v 1.6.4.1.4.1 2008/04/08 21:10:55 jdc Exp $ */\r
+/** @file\r
 \r
-/****************************************************************\r
+  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
 The author of this software is David M. Gay.\r
 \r
@@ -26,6 +33,8 @@ IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\r
 THIS SOFTWARE.\r
 \r
+  $NetBSD: gdtoa.h,v 1.6.4.1.4.1 2008/04/08 21:10:55 jdc Exp\r
+\r
 ****************************************************************/\r
 \r
 /* Please send bug reports to David M. Gay (dmg at acm dot org,\r
@@ -38,10 +47,10 @@ THIS SOFTWARE.
 #include "arith.h"\r
 \r
 #ifndef Long\r
-#define Long EFI_LONG_T\r
+#define Long int32_t\r
 #endif\r
 #ifndef ULong\r
-#define ULong EFI_ULONG_T\r
+#define ULong uint32_t\r
 #endif\r
 #ifndef UShort\r
 #define UShort uint16_t\r
index 3ba2cf8fbf51615d0396a307e4dc2a00e758630e..593b492aa2fc4d6062f3768b7dc207675fb9e3ad 100644 (file)
@@ -9,7 +9,7 @@
   Please send bug reports to David M. Gay (dmg at acm dot org,\r
   with " at " changed at "@" and " dot " changed to ".").\r
 \r
-  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials are licensed and made available under\r
   the terms and conditions of the BSD License that accompanies this distribution.\r
   The full text of the license may be found at\r
@@ -179,8 +179,8 @@ $NetBSD: gdtoaimp.h,v 1.5.4.1 2007/05/07 19:49:06 pavel Exp
 #include <stdint.h>\r
 #define Short   int16_t\r
 #define UShort uint16_t\r
-#define Long   EFI_LONG_T\r
-#define ULong  EFI_ULONG_T\r
+#define Long    int32_t\r
+#define ULong  uint32_t\r
 #define LLong   int64_t\r
 #define ULLong uint64_t\r
 \r
@@ -283,6 +283,13 @@ extern "C" {
 Exactly one of IEEE_LITTLE_ENDIAN, IEEE_BIG_ENDIAN, VAX, or IBM should be defined.\r
 #endif\r
 \r
+/*  This union assumes that:\r
+      sizeof(double) == 8\r
+      sizeof(UINT32) == 4\r
+\r
+    If this is not the case, the type and dimension of the L member will\r
+    have to be modified.\r
+*/\r
 typedef union { double d; UINT32 L[2]; } U;\r
 \r
 #ifdef YES_ALIAS\r
@@ -296,13 +303,13 @@ typedef union { double d; UINT32 L[2]; } U;
 #endif\r
 #else /* !YES_ALIAS */\r
 #ifdef IEEE_LITTLE_ENDIAN\r
-#define word0(x) ( /* LINTED */ (U*)&x)->L[1]\r
-#define word1(x) ( /* LINTED */ (U*)&x)->L[0]\r
+#define word0(x)  ( /* LINTED */ (U*)&x)->L[1]\r
+#define word1(x)  ( /* LINTED */ (U*)&x)->L[0]\r
 #else\r
-#define word0(x) ( /* LINTED */ (U*)&x)->L[0]\r
-#define word1(x) ( /* LINTED */ (U*)&x)->L[1]\r
+#define word0(x)  ( /* LINTED */ (U*)&x)->L[0]\r
+#define word1(x)  ( /* LINTED */ (U*)&x)->L[1]\r
 #endif\r
-#define dval(x) ( /* LINTED */ (U*)&x)->d\r
+#define dval(x)   ( /* LINTED */ (U*)&x)->d\r
 #endif /* YES_ALIAS */\r
 \r
 /* The following definition of Storeinc is appropriate for MIPS processors.\r