Return to BSD News archive
Newsgroups: comp.os.386bsd.bugs Path: sserve!newshost.anu.edu.au!munnari.oz.au!news.Hawaii.Edu!ames!elroy.jpl.nasa.gov!swrinde!gatech!europa.eng.gtefsd.com!darwin.sura.net!newsserver.jvnc.net!yale.edu!nigel.msen.com!math.fu-berlin.de!uniol!tapir.NOC.FH-Lippe.DE!bi-link.owl.de!martin From: martin@bi-link.owl.de (Martin Husemann) Subject: ctype.h Bug & Fix Organization: IN - individual network, Ostwestfalen-Lippe, FRG Date: Wed, 14 Jul 1993 20:40:35 GMT Message-ID: <CA69Fo.Lwv@bi-link.owl.de> Lines: 45 There is a small bug in /usr/include/ctype.h: toupper() and tolower() are expected (by the ANSI standard at least) to work proper on all characters. They don't: toupper will try to convert an uppercase letter as well. The fix is easy: #define toupper(c) (islower(c)?((c) - 'a' + 'A'):(c)) #define tolower(c) (isupper(c)?((c) - 'A' + 'a'):(c)) Of course, there are some illegal uses of this macros. Remember: arguments to macros should *never* have side effects like in *cp++ = toupper(*dev++); An example is in /usr/src/usr.sbin/config/mkheaders.c, which should be fixed like this: /* * convert a dev name to a macro name */ char *tomacro(dev) register char *dev; { static char mbuf[20]; register char *cp; cp = mbuf; *cp++ = 'N'; while (*dev) { *cp++ = toupper(*dev); dev++; } *cp++ = 0; return (mbuf); } Martin -- "In computer languages, beauty is only scan deep" - Larry Wall