Commit d4be151b authored by André Goddard Rosa's avatar André Goddard Rosa Committed by Linus Torvalds

vsprintf: move local vars to block local vars and remove unneeded ones

Cleanup by moving variables closer to the scope where they're used in fact.
Also, remove unneeded ones.
Signed-off-by: default avatarAndré Goddard Rosa <andre.goddard@gmail.com>
Acked-by: default avatarFrederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent b5ff992b
...@@ -892,8 +892,8 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr, ...@@ -892,8 +892,8 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr,
case 'F': case 'F':
case 'f': case 'f':
ptr = dereference_function_descriptor(ptr); ptr = dereference_function_descriptor(ptr);
case 's':
/* Fallthrough */ /* Fallthrough */
case 's':
case 'S': case 'S':
return symbol_string(buf, end, ptr, spec, *fmt); return symbol_string(buf, end, ptr, spec, *fmt);
case 'R': case 'R':
...@@ -1156,8 +1156,7 @@ static int format_decode(const char *fmt, struct printf_spec *spec) ...@@ -1156,8 +1156,7 @@ static int format_decode(const char *fmt, struct printf_spec *spec)
int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
{ {
unsigned long long num; unsigned long long num;
char *str, *end, c; char *str, *end;
int read;
struct printf_spec spec = {0}; struct printf_spec spec = {0};
/* Reject out-of-range values early. Large positive sizes are /* Reject out-of-range values early. Large positive sizes are
...@@ -1176,8 +1175,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) ...@@ -1176,8 +1175,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
while (*fmt) { while (*fmt) {
const char *old_fmt = fmt; const char *old_fmt = fmt;
int read = format_decode(fmt, &spec);
read = format_decode(fmt, &spec);
fmt += read; fmt += read;
...@@ -1201,7 +1199,9 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) ...@@ -1201,7 +1199,9 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
spec.precision = va_arg(args, int); spec.precision = va_arg(args, int);
break; break;
case FORMAT_TYPE_CHAR: case FORMAT_TYPE_CHAR: {
char c;
if (!(spec.flags & LEFT)) { if (!(spec.flags & LEFT)) {
while (--spec.field_width > 0) { while (--spec.field_width > 0) {
if (str < end) if (str < end)
...@@ -1220,6 +1220,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) ...@@ -1220,6 +1220,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
++str; ++str;
} }
break; break;
}
case FORMAT_TYPE_STR: case FORMAT_TYPE_STR:
str = string(str, end, va_arg(args, char *), spec); str = string(str, end, va_arg(args, char *), spec);
...@@ -1464,7 +1465,6 @@ int vbin_printf(u32 *bin_buf, size_t size, const char *fmt, va_list args) ...@@ -1464,7 +1465,6 @@ int vbin_printf(u32 *bin_buf, size_t size, const char *fmt, va_list args)
{ {
struct printf_spec spec = {0}; struct printf_spec spec = {0};
char *str, *end; char *str, *end;
int read;
str = (char *)bin_buf; str = (char *)bin_buf;
end = (char *)(bin_buf + size); end = (char *)(bin_buf + size);
...@@ -1490,12 +1490,14 @@ do { \ ...@@ -1490,12 +1490,14 @@ do { \
} while (0) } while (0)
while (*fmt) { while (*fmt) {
read = format_decode(fmt, &spec); int read = format_decode(fmt, &spec);
fmt += read; fmt += read;
switch (spec.type) { switch (spec.type) {
case FORMAT_TYPE_NONE: case FORMAT_TYPE_NONE:
case FORMAT_TYPE_INVALID:
case FORMAT_TYPE_PERCENT_CHAR:
break; break;
case FORMAT_TYPE_WIDTH: case FORMAT_TYPE_WIDTH:
...@@ -1528,12 +1530,6 @@ do { \ ...@@ -1528,12 +1530,6 @@ do { \
fmt++; fmt++;
break; break;
case FORMAT_TYPE_PERCENT_CHAR:
break;
case FORMAT_TYPE_INVALID:
break;
case FORMAT_TYPE_NRCHARS: { case FORMAT_TYPE_NRCHARS: {
/* skip %n 's argument */ /* skip %n 's argument */
int qualifier = spec.qualifier; int qualifier = spec.qualifier;
...@@ -1606,10 +1602,9 @@ EXPORT_SYMBOL_GPL(vbin_printf); ...@@ -1606,10 +1602,9 @@ EXPORT_SYMBOL_GPL(vbin_printf);
*/ */
int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
{ {
unsigned long long num;
char *str, *end, c;
const char *args = (const char *)bin_buf;
struct printf_spec spec = {0}; struct printf_spec spec = {0};
char *str, *end;
const char *args = (const char *)bin_buf;
if (WARN_ON_ONCE((int) size < 0)) if (WARN_ON_ONCE((int) size < 0))
return 0; return 0;
...@@ -1639,10 +1634,8 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) ...@@ -1639,10 +1634,8 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
} }
while (*fmt) { while (*fmt) {
int read;
const char *old_fmt = fmt; const char *old_fmt = fmt;
int read = format_decode(fmt, &spec);
read = format_decode(fmt, &spec);
fmt += read; fmt += read;
...@@ -1666,7 +1659,9 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) ...@@ -1666,7 +1659,9 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
spec.precision = get_arg(int); spec.precision = get_arg(int);
break; break;
case FORMAT_TYPE_CHAR: case FORMAT_TYPE_CHAR: {
char c;
if (!(spec.flags & LEFT)) { if (!(spec.flags & LEFT)) {
while (--spec.field_width > 0) { while (--spec.field_width > 0) {
if (str < end) if (str < end)
...@@ -1684,11 +1679,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) ...@@ -1684,11 +1679,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
++str; ++str;
} }
break; break;
}
case FORMAT_TYPE_STR: { case FORMAT_TYPE_STR: {
const char *str_arg = args; const char *str_arg = args;
size_t len = strlen(str_arg); args += strlen(str_arg) + 1;
args += len + 1;
str = string(str, end, (char *)str_arg, spec); str = string(str, end, (char *)str_arg, spec);
break; break;
} }
...@@ -1700,11 +1695,6 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) ...@@ -1700,11 +1695,6 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
break; break;
case FORMAT_TYPE_PERCENT_CHAR: case FORMAT_TYPE_PERCENT_CHAR:
if (str < end)
*str = '%';
++str;
break;
case FORMAT_TYPE_INVALID: case FORMAT_TYPE_INVALID:
if (str < end) if (str < end)
*str = '%'; *str = '%';
...@@ -1715,15 +1705,15 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) ...@@ -1715,15 +1705,15 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
/* skip */ /* skip */
break; break;
default: default: {
unsigned long long num;
switch (spec.type) { switch (spec.type) {
case FORMAT_TYPE_LONG_LONG: case FORMAT_TYPE_LONG_LONG:
num = get_arg(long long); num = get_arg(long long);
break; break;
case FORMAT_TYPE_ULONG: case FORMAT_TYPE_ULONG:
num = get_arg(unsigned long);
break;
case FORMAT_TYPE_LONG: case FORMAT_TYPE_LONG:
num = get_arg(unsigned long); num = get_arg(unsigned long);
break; break;
...@@ -1753,8 +1743,9 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) ...@@ -1753,8 +1743,9 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
} }
str = number(str, end, num, spec); str = number(str, end, num, spec);
} } /* default: */
} } /* switch(spec.type) */
} /* while(*fmt) */
if (size > 0) { if (size > 0) {
if (str < end) if (str < end)
...@@ -1808,7 +1799,7 @@ int vsscanf(const char *buf, const char *fmt, va_list args) ...@@ -1808,7 +1799,7 @@ int vsscanf(const char *buf, const char *fmt, va_list args)
char digit; char digit;
int num = 0; int num = 0;
int qualifier, base, field_width; int qualifier, base, field_width;
int is_sign = 0; bool is_sign;
while (*fmt && *str) { while (*fmt && *str) {
/* skip any white space in format */ /* skip any white space in format */
...@@ -1864,12 +1855,13 @@ int vsscanf(const char *buf, const char *fmt, va_list args) ...@@ -1864,12 +1855,13 @@ int vsscanf(const char *buf, const char *fmt, va_list args)
} }
} }
} }
base = 10;
is_sign = 0;
if (!*fmt || !*str) if (!*fmt || !*str)
break; break;
base = 10;
is_sign = 0;
switch (*fmt++) { switch (*fmt++) {
case 'c': case 'c':
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment