aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAndré Goddard Rosa <andre.goddard@gmail.com>2009-12-14 21:00:59 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2009-12-15 11:53:32 -0500
commitd4be151b2180fbbc6729dfaa16280d150e3fab1f (patch)
tree2b82f9cd79144f04804db07384d4fdaf346b2ed8 /lib
parentb5ff992b09dbe06a4a020fbb702e29ab61290cc5 (diff)
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: André Goddard Rosa <andre.goddard@gmail.com> Acked-by: Frederic Weisbecker <fweisbec@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/vsprintf.c64
1 files changed, 28 insertions, 36 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 4819c3d6cca4..f9532e09b608 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -892,8 +892,8 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr,
892 case 'F': 892 case 'F':
893 case 'f': 893 case 'f':
894 ptr = dereference_function_descriptor(ptr); 894 ptr = dereference_function_descriptor(ptr);
895 case 's':
896 /* Fallthrough */ 895 /* Fallthrough */
896 case 's':
897 case 'S': 897 case 'S':
898 return symbol_string(buf, end, ptr, spec, *fmt); 898 return symbol_string(buf, end, ptr, spec, *fmt);
899 case 'R': 899 case 'R':
@@ -1156,8 +1156,7 @@ qualifier:
1156int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) 1156int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
1157{ 1157{
1158 unsigned long long num; 1158 unsigned long long num;
1159 char *str, *end, c; 1159 char *str, *end;
1160 int read;
1161 struct printf_spec spec = {0}; 1160 struct printf_spec spec = {0};
1162 1161
1163 /* Reject out-of-range values early. Large positive sizes are 1162 /* 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 1175
1177 while (*fmt) { 1176 while (*fmt) {
1178 const char *old_fmt = fmt; 1177 const char *old_fmt = fmt;
1179 1178 int read = format_decode(fmt, &spec);
1180 read = format_decode(fmt, &spec);
1181 1179
1182 fmt += read; 1180 fmt += read;
1183 1181
@@ -1201,7 +1199,9 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
1201 spec.precision = va_arg(args, int); 1199 spec.precision = va_arg(args, int);
1202 break; 1200 break;
1203 1201
1204 case FORMAT_TYPE_CHAR: 1202 case FORMAT_TYPE_CHAR: {
1203 char c;
1204
1205 if (!(spec.flags & LEFT)) { 1205 if (!(spec.flags & LEFT)) {
1206 while (--spec.field_width > 0) { 1206 while (--spec.field_width > 0) {
1207 if (str < end) 1207 if (str < end)
@@ -1220,6 +1220,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
1220 ++str; 1220 ++str;
1221 } 1221 }
1222 break; 1222 break;
1223 }
1223 1224
1224 case FORMAT_TYPE_STR: 1225 case FORMAT_TYPE_STR:
1225 str = string(str, end, va_arg(args, char *), spec); 1226 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{ 1465{
1465 struct printf_spec spec = {0}; 1466 struct printf_spec spec = {0};
1466 char *str, *end; 1467 char *str, *end;
1467 int read;
1468 1468
1469 str = (char *)bin_buf; 1469 str = (char *)bin_buf;
1470 end = (char *)(bin_buf + size); 1470 end = (char *)(bin_buf + size);
@@ -1490,12 +1490,14 @@ do { \
1490} while (0) 1490} while (0)
1491 1491
1492 while (*fmt) { 1492 while (*fmt) {
1493 read = format_decode(fmt, &spec); 1493 int read = format_decode(fmt, &spec);
1494 1494
1495 fmt += read; 1495 fmt += read;
1496 1496
1497 switch (spec.type) { 1497 switch (spec.type) {
1498 case FORMAT_TYPE_NONE: 1498 case FORMAT_TYPE_NONE:
1499 case FORMAT_TYPE_INVALID:
1500 case FORMAT_TYPE_PERCENT_CHAR:
1499 break; 1501 break;
1500 1502
1501 case FORMAT_TYPE_WIDTH: 1503 case FORMAT_TYPE_WIDTH:
@@ -1528,12 +1530,6 @@ do { \
1528 fmt++; 1530 fmt++;
1529 break; 1531 break;
1530 1532
1531 case FORMAT_TYPE_PERCENT_CHAR:
1532 break;
1533
1534 case FORMAT_TYPE_INVALID:
1535 break;
1536
1537 case FORMAT_TYPE_NRCHARS: { 1533 case FORMAT_TYPE_NRCHARS: {
1538 /* skip %n 's argument */ 1534 /* skip %n 's argument */
1539 int qualifier = spec.qualifier; 1535 int qualifier = spec.qualifier;
@@ -1606,10 +1602,9 @@ EXPORT_SYMBOL_GPL(vbin_printf);
1606 */ 1602 */
1607int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf) 1603int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
1608{ 1604{
1609 unsigned long long num;
1610 char *str, *end, c;
1611 const char *args = (const char *)bin_buf;
1612 struct printf_spec spec = {0}; 1605 struct printf_spec spec = {0};
1606 char *str, *end;
1607 const char *args = (const char *)bin_buf;
1613 1608
1614 if (WARN_ON_ONCE((int) size < 0)) 1609 if (WARN_ON_ONCE((int) size < 0))
1615 return 0; 1610 return 0;
@@ -1639,10 +1634,8 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
1639 } 1634 }
1640 1635
1641 while (*fmt) { 1636 while (*fmt) {
1642 int read;
1643 const char *old_fmt = fmt; 1637 const char *old_fmt = fmt;
1644 1638 int read = format_decode(fmt, &spec);
1645 read = format_decode(fmt, &spec);
1646 1639
1647 fmt += read; 1640 fmt += read;
1648 1641
@@ -1666,7 +1659,9 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
1666 spec.precision = get_arg(int); 1659 spec.precision = get_arg(int);
1667 break; 1660 break;
1668 1661
1669 case FORMAT_TYPE_CHAR: 1662 case FORMAT_TYPE_CHAR: {
1663 char c;
1664
1670 if (!(spec.flags & LEFT)) { 1665 if (!(spec.flags & LEFT)) {
1671 while (--spec.field_width > 0) { 1666 while (--spec.field_width > 0) {
1672 if (str < end) 1667 if (str < end)
@@ -1684,11 +1679,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
1684 ++str; 1679 ++str;
1685 } 1680 }
1686 break; 1681 break;
1682 }
1687 1683
1688 case FORMAT_TYPE_STR: { 1684 case FORMAT_TYPE_STR: {
1689 const char *str_arg = args; 1685 const char *str_arg = args;
1690 size_t len = strlen(str_arg); 1686 args += strlen(str_arg) + 1;
1691 args += len + 1;
1692 str = string(str, end, (char *)str_arg, spec); 1687 str = string(str, end, (char *)str_arg, spec);
1693 break; 1688 break;
1694 } 1689 }
@@ -1700,11 +1695,6 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
1700 break; 1695 break;
1701 1696
1702 case FORMAT_TYPE_PERCENT_CHAR: 1697 case FORMAT_TYPE_PERCENT_CHAR:
1703 if (str < end)
1704 *str = '%';
1705 ++str;
1706 break;
1707
1708 case FORMAT_TYPE_INVALID: 1698 case FORMAT_TYPE_INVALID:
1709 if (str < end) 1699 if (str < end)
1710 *str = '%'; 1700 *str = '%';
@@ -1715,15 +1705,15 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
1715 /* skip */ 1705 /* skip */
1716 break; 1706 break;
1717 1707
1718 default: 1708 default: {
1709 unsigned long long num;
1710
1719 switch (spec.type) { 1711 switch (spec.type) {
1720 1712
1721 case FORMAT_TYPE_LONG_LONG: 1713 case FORMAT_TYPE_LONG_LONG:
1722 num = get_arg(long long); 1714 num = get_arg(long long);
1723 break; 1715 break;
1724 case FORMAT_TYPE_ULONG: 1716 case FORMAT_TYPE_ULONG:
1725 num = get_arg(unsigned long);
1726 break;
1727 case FORMAT_TYPE_LONG: 1717 case FORMAT_TYPE_LONG:
1728 num = get_arg(unsigned long); 1718 num = get_arg(unsigned long);
1729 break; 1719 break;
@@ -1753,8 +1743,9 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
1753 } 1743 }
1754 1744
1755 str = number(str, end, num, spec); 1745 str = number(str, end, num, spec);
1756 } 1746 } /* default: */
1757 } 1747 } /* switch(spec.type) */
1748 } /* while(*fmt) */
1758 1749
1759 if (size > 0) { 1750 if (size > 0) {
1760 if (str < end) 1751 if (str < end)
@@ -1808,7 +1799,7 @@ int vsscanf(const char *buf, const char *fmt, va_list args)
1808 char digit; 1799 char digit;
1809 int num = 0; 1800 int num = 0;
1810 int qualifier, base, field_width; 1801 int qualifier, base, field_width;
1811 int is_sign = 0; 1802 bool is_sign;
1812 1803
1813 while (*fmt && *str) { 1804 while (*fmt && *str) {
1814 /* skip any white space in format */ 1805 /* skip any white space in format */
@@ -1864,12 +1855,13 @@ int vsscanf(const char *buf, const char *fmt, va_list args)
1864 } 1855 }
1865 } 1856 }
1866 } 1857 }
1867 base = 10;
1868 is_sign = 0;
1869 1858
1870 if (!*fmt || !*str) 1859 if (!*fmt || !*str)
1871 break; 1860 break;
1872 1861
1862 base = 10;
1863 is_sign = 0;
1864
1873 switch (*fmt++) { 1865 switch (*fmt++) {
1874 case 'c': 1866 case 'c':
1875 { 1867 {