]> git.proxmox.com Git - mirror_edk2.git/blobdiff - StdLib/LibC/Stdio/vfscanf.c
StdLib: Fix printf issues with floating point and wide character strings. Also resol...
[mirror_edk2.git] / StdLib / LibC / Stdio / vfscanf.c
index 724fd2a7474b539f3a8140786c46638c8b18429e..4f84a39c683ae0c2f647d0869acd645e0d4e152b 100644 (file)
@@ -1,11 +1,11 @@
 /** @file\r
     Implementation of scanf internals for <stdio.h>.\r
 \r
-    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
     This program and the accompanying materials are licensed and made available\r
     under the terms and conditions of the BSD License that accompanies this\r
     distribution.  The full text of the license may be found at\r
-    http://opensource.org/licenses/bsd-license.php.\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
     FreeBSD: src/lib/libc/stdio/vfscanf.c,v 1.41 2007/01/09 00:28:07 imp Exp\r
     vfscanf.c 8.1 (Berkeley) 6/4/93\r
 **/\r
-//#include <Uefi.h>               // REMOVE, For DEBUG only\r
-//#include <Library/UefiLib.h>    // REMOVE, For DEBUG only\r
-\r
 #include  <LibConfig.h>\r
 \r
 #include "namespace.h"\r
 #include <assert.h>\r
 #include <ctype.h>\r
+#include  <errno.h>\r
 #include <inttypes.h>\r
 #include <stdio.h>\r
 #include <stdlib.h>\r
@@ -70,7 +68,7 @@
 #endif\r
 \r
 /*\r
- * Provide an external name for vfscanf.  Note, we don't use the normal\r
+ * Provide an external name for vfscanf.  Note, EFI uses the normal\r
  * namespace.h method; stdio routines explicitly use the internal name\r
  * __svfscanf.\r
  */\r
@@ -142,6 +140,10 @@ __svfscanf(FILE *fp, char const *fmt0, va_list ap)
 {\r
   int ret;\r
 \r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (EOF);\r
+  }\r
   FLOCKFILE(fp);\r
   ret = __svfscanf_unlocked(fp, fmt0, ap);\r
   FUNLOCKFILE(fp);\r
@@ -178,6 +180,10 @@ __svfscanf_unlocked(FILE *fp, const char *fmt0, va_list ap)
 \r
   _DIAGASSERT(fp != NULL);\r
   _DIAGASSERT(fmt0 != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (EOF);\r
+  }\r
 \r
   _SET_ORIENTATION(fp, -1);\r
 \r
@@ -837,12 +843,12 @@ literal:
         goto match_failure;\r
       if ((flags & SUPPRESS) == 0) {\r
         if (flags & LONGDBL) {\r
-/*dvm*/   long double **mp = (long double **)ap;\r
+          long double **mp = (long double **)ap;\r
           long double res = strtold(buf, &p);\r
 \r
-/*dvm*/   *(*mp) = res;\r
-/*dvm*/   ap += sizeof(long double *);\r
-/*dvm*/   //*va_arg(ap, long double *) = res;\r
+          *(*mp) = res;\r
+          ap += sizeof(long double *);\r
+/*???*/   //*va_arg(ap, long double *) = res;\r
         } else if (flags & LONG) {\r
           double res = strtod(buf, &p);\r
           *va_arg(ap, double *) = res;\r
@@ -989,6 +995,11 @@ parsefloat(FILE *fp, char *buf, char *end)
   char decpt = *localeconv()->decimal_point;\r
   _Bool gotmantdig = 0, ishex = 0;\r
 \r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (EOF);\r
+  }\r
+\r
   /*\r
    * We set commit = p whenever the string we have read so far\r
    * constitutes a valid representation of a floating point\r