ref: 95b6c63659cb4fa379a56778c32093728dc74c1a
parent: a0c0a97c3cb0a12e7b0d3bfc47b89506e9eb78cb
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Dec 5 16:11:59 EST 2017
[lib/c] Simplify vfprintf() This is the good thing of undefined behaviour, you can ignore a lot of cases and it is a programmer fault, not a library fault.
--- a/lib/c/src/vfprintf.c
+++ b/lib/c/src/vfprintf.c
@@ -137,8 +137,6 @@
len *= sizeof(wchar_t);
adjust = (len < width) ? width - len : 0;
- if (adjust > SIZE_MAX - len)
- return SIZE_MAX;
cnt = adjust + len;
if (left)
adjust = -adjust;
@@ -167,8 +165,6 @@
}
adjust = (len < width) ? width - len : 0;
- if (adjust > SIZE_MAX - len)
- return SIZE_MAX;
cnt = adjust + len;
if (left)
adjust = -adjust;
@@ -208,13 +204,12 @@
struct conv conv;
char buf[MAXPREC+1];
wchar_t wbuf[2];
- typedef unsigned char uchar;
for (cnt = 0; ch = *fmt++; cnt += inc) {
if (ch != '%') {
putc(ch, fp);
inc = 1;
- goto test_inc;
+ continue;
}
fill = ' ';
@@ -241,7 +236,7 @@
fmt++;
n = va_arg(va, int);
} else {
- for (n = 0; isdigit(ch = (uchar) *fmt); fmt++)
+ for (n = 0; isdigit(ch = *fmt); fmt++)
n = n * 10 + ch - '0';
}
if (n > MAXPREC)
@@ -265,7 +260,7 @@
case '8':
case '9':
--fmt;
- for (n = 0; isdigit(ch = (uchar) *fmt); ++fmt)
+ for (n = 0; isdigit(ch = *fmt); ++fmt)
n = n * 10 + ch - '0';
if (left)
n = -n;
@@ -366,11 +361,6 @@
break;
case '\0':
goto out_loop;
- }
-test_inc:
- if (inc == SIZE_MAX || inc > INT_MAX - cnt) {
- errno = EOVERFLOW;
- return EOF;
}
}