[PATCH 1/2] vsprintf: Specify type for union val members

Thomas Preston
2018-12-11T15:21:32Z

The vsscanf function uses implicit type casting to populate the long
long integers in union val from the obsolete functions simple_strtol()
and simple_strtoll(). However the new functions kstrtol() and kstrtoll()
expect a pointer to the correct type, so we must be explicit about which
type we are using.

Signed-off-by: Thomas Preston <thomas.preston@codethink.co.uk>
---
lib/vsprintf.c | 34 +++++++++++++++++-----------------
1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 37a54a6dd594..bbf2ac734711 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -2914,8 +2914,8 @@ int vsscanf(const char *buf, const char *fmt, va_list args)
u8 qualifier;
unsigned int base;
union {
- long long s;
- unsigned long long u;
+ long long sll;
+ unsigned long long ull;
} val;
s16 field_width;
bool is_sign;
@@ -3120,11 +3120,11 @@ int vsscanf(const char *buf, const char *fmt, va_list args)
break;

if (is_sign)
- val.s = qualifier != 'L' ?
+ val.sll = qualifier != 'L' ?
simple_strtol(str, &next, base) :
simple_strtoll(str, &next, base);
else
- val.u = qualifier != 'L' ?
+ val.ull = qualifier != 'L' ?
simple_strtoul(str, &next, base) :
simple_strtoull(str, &next, base);

@@ -3133,9 +3133,9 @@ int vsscanf(const char *buf, const char *fmt, va_list args)
_parse_integer_fixup_radix(str, &base);
while (next - str > field_width) {
if (is_sign)
- val.s = div_s64(val.s, base);
+ val.sll = div_s64(val.sll, base);
else
- val.u = div_u64(val.u, base);
+ val.ull = div_u64(val.ull, base);
--next;
}
}
@@ -3143,36 +3143,36 @@ int vsscanf(const char *buf, const char *fmt, va_list args)
switch (qualifier) {
case 'H': /* that's 'hh' in format */
if (is_sign)
- *va_arg(args, signed char *) = val.s;
+ *va_arg(args, signed char *) = val.sll;
else
- *va_arg(args, unsigned char *) = val.u;
+ *va_arg(args, unsigned char *) = val.ull;
break;
case 'h':
if (is_sign)
- *va_arg(args, short *) = val.s;
+ *va_arg(args, short *) = val.sll;
else
- *va_arg(args, unsigned short *) = val.u;
+ *va_arg(args, unsigned short *) = val.ull;
break;
case 'l':
if (is_sign)
- *va_arg(args, long *) = val.s;
+ *va_arg(args, long *) = val.sll;
else
- *va_arg(args, unsigned long *) = val.u;
+ *va_arg(args, unsigned long *) = val.ull;
break;
case 'L':
if (is_sign)
- *va_arg(args, long long *) = val.s;
+ *va_arg(args, long long *) = val.sll;
else
- *va_arg(args, unsigned long long *) = val.u;
+ *va_arg(args, unsigned long long *) = val.ull;
break;
case 'z':
- *va_arg(args, size_t *) = val.u;
+ *va_arg(args, size_t *) = val.ull;
break;
default:
if (is_sign)
- *va_arg(args, int *) = val.s;
+ *va_arg(args, int *) = val.sll;
else
- *va_arg(args, unsigned int *) = val.u;
+ *va_arg(args, unsigned int *) = val.ull;
break;
}
num++;
--
2.11.0