summary refs log tree commit diff
path: root/stdio-common
diff options
context:
space:
mode:
Diffstat (limited to 'stdio-common')
-rw-r--r--stdio-common/printf-parse.h4
-rw-r--r--stdio-common/reg-printf.c19
2 files changed, 15 insertions, 8 deletions
diff --git a/stdio-common/printf-parse.h b/stdio-common/printf-parse.h
index 78811701bb..eff2816607 100644
--- a/stdio-common/printf-parse.h
+++ b/stdio-common/printf-parse.h
@@ -117,7 +117,7 @@ find_spec (const UCHAR_T *format, mbstate_t *ps)
 
 
 /* These are defined in reg-printf.c.  */
-extern printf_arginfo_function *__printf_arginfo_table[] attribute_hidden;
+extern printf_arginfo_function **__printf_arginfo_table attribute_hidden;
 extern printf_function **__printf_function_table attribute_hidden;
 
 
@@ -354,7 +354,7 @@ parse_one_spec (const UCHAR_T *format, size_t posn, struct printf_spec *spec,
 
   /* Get the format specification.  */
   spec->info.spec = (wchar_t) *format++;
-  if (__printf_function_table != NULL
+  if (__builtin_expect (__printf_function_table != NULL, 0)
       && spec->info.spec <= UCHAR_MAX
       && __printf_arginfo_table[spec->info.spec] != NULL)
     /* We don't try to get the types for all arguments if the format
diff --git a/stdio-common/reg-printf.c b/stdio-common/reg-printf.c
index fe49633932..c42040ec3a 100644
--- a/stdio-common/reg-printf.c
+++ b/stdio-common/reg-printf.c
@@ -21,10 +21,8 @@
 #include <printf.h>
 
 /* Array of functions indexed by format character.  */
-static printf_function *printf_funcs[UCHAR_MAX + 1];
-printf_arginfo_function *__printf_arginfo_table[UCHAR_MAX + 1]
-     attribute_hidden;
-
+libc_freeres_ptr (printf_arginfo_function **__printf_arginfo_table)
+  attribute_hidden;
 printf_function **__printf_function_table attribute_hidden;
 
 int __register_printf_function __P ((int, printf_function,
@@ -43,9 +41,18 @@ __register_printf_function (spec, converter, arginfo)
       return -1;
     }
 
-  __printf_function_table = printf_funcs;
+  if (__printf_function_table == NULL)
+    {
+      __printf_arginfo_table = (printf_arginfo_function **)
+	malloc ((UCHAR_MAX + 1) * sizeof (void *) * 2);
+      if (__printf_arginfo_table == NULL)
+	return -1;
+      __printf_function_table = (printf_function **)
+	(__printf_arginfo_table + UCHAR_MAX + 1);
+    }
+
+  __printf_function_table[spec] = converter;
   __printf_arginfo_table[spec] = arginfo;
-  printf_funcs[spec] = converter;
 
   return 0;
 }