eesrajm@cc.brunel.ac.uk (Andrew J Michael) (08/29/90)
Duncan Grant, one of the customers of The MINIX Centre, has pointed out a couple of bugs with scanf(). The %c and %[...] arguments skip whitespace when they shouldn't, and the %h argument is not implemented. He provided a patch against 1.3, which I have modified for 1.5.10. Note that patch will tell you that the diff is offset by 11 lines - this is due to the presence of RCS headers in my source. Andy Michael ------- snip, snip ---------------------------- *** /tmp/,RCSt1000196 Mon Aug 27 10:30:54 1990 --- scanf.c Mon Aug 27 10:29:25 1990 *************** *** 13,18 **** --- 16,25 ---- #include <stdarg.h> /* scanf - formatted input conversion Author: Patrick van Kleef */ + /* Modified by Duncan Grant 10 July '90 to remove whitespace skips + with %c and %[..]; and to recognise the 'h' size specifier. + */ + #include <stdio.h> #include <ctype.h> *************** *** 46,51 **** --- 53,59 ---- union ptr_union { char *chr_p; + unsigned short *ushort_p; unsigned int *uint_p; unsigned long *ulong_p; }; *************** *** 113,118 **** --- 121,127 ---- unsigned width; /* width of field */ int widflag; /* width was specified */ int longflag; /* true if long */ + int shortflag; /* true if short */ int done_some; /* true if we have seen some data */ int reverse; /* reverse the checking in [...] */ char *endbracket; /* position of the ] in format string */ *************** *** 154,160 **** width = (unsigned) UINT_MAX; /* very wide */ } if (longflag = (tolower(*format) == 'l')) ++format; ! if (*format != 'c') while (isspace(ic)) rnc(); done_some = 0; /* nothing yet */ switch (*format) { --- 163,171 ---- width = (unsigned) UINT_MAX; /* very wide */ } if (longflag = (tolower(*format) == 'l')) ++format; ! if (shortflag = (tolower (*format) == 'h')) ++format; ! if ((*format != 'c') && (*format != '[')) ! while (isspace(ic)) rnc(); done_some = 0; /* nothing yet */ switch (*format) { *************** *** 248,254 **** *endbracket = '\0'; /* change format string */ ! while (width-- && !isspace(ic) && ic > 0 && (scnindex(ic, format) ^ reverse)) { if (do_assign) *(argp)->chr_p++ = (char) ic; rnc(); --- 259,265 ---- *endbracket = '\0'; /* change format string */ ! while (width-- && ic > 0 && (scnindex(ic, format) ^ reverse)) { if (do_assign) *(argp)->chr_p++ = (char) ic; rnc(); -- Andy Michael (eesrajm@cc.brunel.ac.uk) " Software cannot be written to 85 Hawthorne Crescent be completely free of errors." West Drayton Middlesex - Acorn Computers Ltd. UB7 9PA