summaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorManuel Novoa III <mjn3@codepoet.org>2001-03-23 02:32:39 +0000
committerManuel Novoa III <mjn3@codepoet.org>2001-03-23 02:32:39 +0000
commit8625fbfe454b90a1a6f24e365cb0fff672414cff (patch)
treea0ae6b320d490b0b8eb3f1baa339ad60fab9b4f8 /libc
parentfec38619dc00c09d59ce092c7a2fa09d83ff22e1 (diff)
Bug fix from Peter Kjellerstedt <Peter.Kjellerstedt@axis.com>.
Diffstat (limited to 'libc')
-rw-r--r--libc/stdio/scanf.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/libc/stdio/scanf.c b/libc/stdio/scanf.c
index 0f1843a4d..a8f9f0ed0 100644
--- a/libc/stdio/scanf.c
+++ b/libc/stdio/scanf.c
@@ -139,6 +139,7 @@ struct scan_cookie {
FILE *fp;
int nread;
int width;
+ int width_flag;
int ungot_char;
int ungot_flag;
};
@@ -166,6 +167,7 @@ static void init_scan_cookie(struct scan_cookie *sc, FILE *fp)
{
sc->fp = fp;
sc->nread = 0;
+ sc->width_flag = 0;
sc->ungot_flag = 0;
if ((sc->ungot_char = getc(fp)) > 0) { /* not EOF or EOS */
sc->ungot_flag = 1;
@@ -182,6 +184,7 @@ static int scan_getc_nw(struct scan_cookie *sc)
if (sc->ungot_char > 0) {
++sc->nread;
}
+ sc->width_flag = 0;
return sc->ungot_char;
}
@@ -190,6 +193,7 @@ static int scan_getc(struct scan_cookie *sc)
if (sc->ungot_flag == 0) {
sc->ungot_char = getc(sc->fp);
}
+ sc->width_flag = 1;
if (--sc->width < 0) {
sc->ungot_flag = 1;
return 0;
@@ -207,6 +211,9 @@ static void scan_ungetc(struct scan_cookie *sc)
assert(sc->width < 0);
return;
}
+ if (sc->width_flag) {
+ ++sc->width;
+ }
sc->ungot_flag = 1;
if (sc->ungot_char > 0) { /* not EOF or EOS */
--sc->nread;