diff options
author | tjr <tjr@FreeBSD.org> | 2003-07-05 03:39:23 +0000 |
---|---|---|
committer | tjr <tjr@FreeBSD.org> | 2003-07-05 03:39:23 +0000 |
commit | 8f7372609c4d39f3a011b2791b837d21a33be8be (patch) | |
tree | 4577d9f8d1aea236edbc20e841e66435a385c2de /lib/libc | |
parent | c80ccf2b5d12216d4a075bc28f8c087e5be7b103 (diff) | |
download | FreeBSD-src-8f7372609c4d39f3a011b2791b837d21a33be8be.zip FreeBSD-src-8f7372609c4d39f3a011b2791b837d21a33be8be.tar.gz |
Fix two incorrect uses of sizeof: we need to divide the size of the buffer
by sizeof(wchar_t) to get the number of wide characters it contains.
Remove the !hardway micro-optimisation from the CT_INT case to avoid
having to fix it for wide characters.
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/stdio/vfwscanf.c | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/lib/libc/stdio/vfwscanf.c b/lib/libc/stdio/vfwscanf.c index 7723bc5..990555c 100644 --- a/lib/libc/stdio/vfwscanf.c +++ b/lib/libc/stdio/vfwscanf.c @@ -542,15 +542,9 @@ literal: case CT_INT: /* scan an integer as if by the conversion function */ -#ifdef hardway - if (width == 0 || width > sizeof(buf) - 1) - width = sizeof(buf) - 1; -#else - /* size_t is unsigned, hence this optimisation */ - if (--width > sizeof(buf) - 2) - width = sizeof(buf) - 2; - width++; -#endif + if (width == 0 || width > sizeof(buf) / + sizeof(*buf) - 1) + width = sizeof(buf) / sizeof(*buf) - 1; flags |= SIGNOK | NDIGITS | NZDIGITS; for (p = buf; width; width--) { c = __fgetwc(fp); @@ -692,8 +686,9 @@ literal: #ifdef FLOATING_POINT case CT_FLOAT: /* scan a floating point number as if by strtod */ - if (width == 0 || width > sizeof(buf) - 1) - width = sizeof(buf) - 1; + if (width == 0 || width > sizeof(buf) / + sizeof(*buf) - 1) + width = sizeof(buf) / sizeof(*buf) - 1; if ((width = parsefloat(fp, buf, buf + width)) == 0) goto match_failure; if ((flags & SUPPRESS) == 0) { |