Переглянути джерело

At least cope with "%llx" by reading the correct-sized va_arg from the

stack, even if we don't yet print it out.

At some point, vsprintf() needs to be fixed up so that it can correctly
cope with limited-sized buffers (i.e. vsnprintf), long longs, and
standard format specifiers (e.g. "%04x").  We should also remove the
special types (MAC addresses and IP addresses).  This would then enable
us to use gcc's ability to type-check printf format strings.
tags/v0.9.3
Michael Brown 18 роки тому
джерело
коміт
f99e7a375e
1 змінених файлів з 16 додано та 7 видалено
  1. 16
    7
      src/core/vsprintf.c

+ 16
- 7
src/core/vsprintf.c Переглянути файл

@@ -5,10 +5,11 @@
5 5
 #include "errno.h"
6 6
 #include "vsprintf.h"
7 7
 
8
-#define LONG_SHIFT  ((int)((sizeof(unsigned long)*CHAR_BIT) - 4))
9
-#define INT_SHIFT   ((int)((sizeof(unsigned int)*CHAR_BIT) - 4))
10
-#define SHRT_SHIFT  ((int)((sizeof(unsigned short)*CHAR_BIT) - 4))
11
-#define CHAR_SHIFT  ((int)((sizeof(unsigned char)*CHAR_BIT) - 4))
8
+#define LONGLONG_SHIFT	((int)((sizeof(unsigned long long)*CHAR_BIT) - 4))
9
+#define LONG_SHIFT	((int)((sizeof(unsigned long)*CHAR_BIT) - 4))
10
+#define INT_SHIFT	((int)((sizeof(unsigned int)*CHAR_BIT) - 4))
11
+#define SHRT_SHIFT	((int)((sizeof(unsigned short)*CHAR_BIT) - 4))
12
+#define CHAR_SHIFT	((int)((sizeof(unsigned char)*CHAR_BIT) - 4))
12 13
 
13 14
 /** @file */
14 15
 
@@ -62,7 +63,11 @@ static int vsprintf(char *buf, const char *fmt, va_list args)
62 63
 				shift = LONG_SHIFT;
63 64
 				fmt++;
64 65
 			}
65
-			else if (*fmt == 'h') {
66
+			if (*fmt == 'l') {
67
+				shift = LONGLONG_SHIFT;
68
+				fmt++;
69
+			}
70
+			if (*fmt == 'h') {
66 71
 				shift = SHRT_SHIFT;
67 72
 				fmt++;
68 73
 				if (*fmt == 'h') {
@@ -79,7 +84,9 @@ static int vsprintf(char *buf, const char *fmt, va_list args)
79 84
 				/* With x86 gcc, sizeof(long) == sizeof(int) */
80 85
 				unsigned long h;
81 86
 				int ncase;
82
-				if (shift > INT_SHIFT) {
87
+				if (shift > LONG_SHIFT) {
88
+					h = va_arg(args, unsigned long long);
89
+				} else if (shift > INT_SHIFT) {
83 90
 					h = va_arg(args, unsigned long);
84 91
 				} else {
85 92
 					h = va_arg(args, unsigned int);
@@ -95,7 +102,9 @@ static int vsprintf(char *buf, const char *fmt, va_list args)
95 102
 			else if (*fmt == 'd') {
96 103
 				char *r, *t;
97 104
 				long i;
98
-				if (shift > INT_SHIFT) {
105
+				if (shift > LONG_SHIFT) {
106
+					i = va_arg(args, long long);
107
+				} else if (shift > INT_SHIFT) {
99 108
 					i = va_arg(args, long);
100 109
 				} else {
101 110
 					i = va_arg(args, int);

Завантаження…
Відмінити
Зберегти