peter@sugar.UUCP (08/29/87)
The following program will not work with the printf(""); taken out. It appears that stdio() doesn't come up properly initted. This is a bug. You should be able to interleaf printf() and putchar() in any order. Without that printf there, the output consists of a single linefeed unless argv[1][0] is alphabetic. The purpose of the program, bu the way, is to strip dubious characters off input read from shell scripts in a UNIX bbs. #include <stdio.h> #include <ctype.h> main(ac, av) int ac; char **av; { printf(""); /* needed! */ while(*++av) { while(**av) { if(isdigit(**av)) break; if(isupper(**av)) break; if(islower(**av)) break; if(strchr(**av, "-_=+")) break; ++*av; } while(isalnum(**av) || strchr(**av, ".-_=+")) { putchar(**av); ++*av; } putchar(' '); } putchar('\n'); } -- -- Peter da Silva `-_-' ...!seismo!soma!uhnix1!sugar!peter -- U <--- not a copyrighted cartoon :->
root@hobbes.UUCP (08/31/87)
+---- Peter da Silva writes the following in article <593@sugar.UUCP> ---- | [[ concerning a "supposed" bug in Microport SV/AT ]] | The following program will not work with the printf(""); taken out. It | appears that stdio() doesn't come up properly initted. This is a bug. | You should be able to interleaf printf() and putchar() in any order. | | #include <stdio.h> | #include <ctype.h> | main(ac, av) int ac; char **av; | { | printf(""); /* needed! */ | while(*++av) { | while(**av) { | if(isdigit(**av)) break; | if(isupper(**av)) break; | if(islower(**av)) break; | if(strchr(**av, "-_=+")) break; | ++*av; | } | while(isalnum(**av) || strchr(**av, ".-_=+")) { | putchar(**av); | ++*av; | } | putchar(' '); | } | putchar('\n'); | } +---- Not a bug in stdio - replace the "printf("");" with "strlen("");" and it works, too. The *REAL* bug is that your code is corrupting the stack, specifically the call to strchr(). You have reversed the arguments to the function. From the S5r2 man page string(3C): char *strchr(s, c) char *s; int c; I *hate* it when people blame the OS for their simple programming errors. I used lint to find this one: % lint x.c x.c ============== (37) warning: main() returns random value to invocation environment warning: argument unused in function: (37) ac in main ============== value type used inconsistently strchr llib-lc(424) :: x.c(27) strchr llib-lc(424) :: x.c(30) value type declared inconsistently strchr llib-lc(424) :: x.c(30) function argument ( number ) used inconsistently strchr( arg 1 ) llib-lc(424) :: x.c(27) strchr( arg 2 ) llib-lc(424) :: x.c(27) strchr( arg 1 ) llib-lc(424) :: x.c(30) strchr( arg 2 ) llib-lc(424) :: x.c(30) function returns value which is always ignored putchar FLAME ON: Why don't *you* use it? That's what its for! FLAME OFF! -- John Plocher uwvax!geowhiz!uwspan!plocher plocher%uwspan.UUCP@uwvax.CS.WISC.EDU
peter@sugar.UUCP (09/01/87)
In article <202@hobbes.UUCP>, root@hobbes.UUCP (John Plocher) writes: > +---- Peter da Silva writes the following in article <593@sugar.UUCP> ---- > | [[ concerning a "supposed" bug in Microport SV/AT ]] > Not a bug in stdio - replace the "printf("");" with "strlen("");" and it works, > too. The *REAL* bug is that your code is corrupting the stack, specifically > the call to strchr(). You have reversed the arguments to the function. You're right. My only possible excuse is I'm a Version 7 fan from way, and I don't see any good reason for renaming "index()" as "strchr()"... I have a mental block about strchr() as a result. And don't flame me about index and strchr having the same arguments. I've just recently weaned myself off #defining them. I also misspelled "interleave" as "interleaf" in my message. > FLAME ON: Why don't *you* use it? That's what its for! FLAME OFF! [what was the name of the guy in the comix who does this? The human torch?] I don't know why I don't use lint... probably because I've pretty much got all the libraries memorised by now (except for the aforementioned mental block) and this is about the only error that lint catches and the compilers don't anymore. I also do a *lot* of 'C' programming in environments where lint doesn't exist. After you've linted to no avail enough times you get turned off it. When ANSI 'C' function prototypes become widely available lint will go the way of all flesh. PS: I can't quite figure out how strchr could be corrupting the stack. The calling argument does all the pushing and popping, strchr never modifies its arguments, and the size of the arguments is the same either way. If strchr *is* clobbering the stack, that's possibly a bug in strchr. Well, at least a design flaw. -- -- Peter da Silva `-_-' ...!seismo!soma!uhnix1!sugar!peter -- U <--- not a copyrighted cartoon :->