dce@mips.COM (David Elliott) (09/03/88)
In article <15741@shemp.CS.UCLA.EDU> casey@admin.cognet.ucla.edu.UUCP (Casey Leedom) writes: >In article <1334@solo7.cs.vu.nl> maart@cs.vu.nl () writes: >> 'sed -e' without any further argument dumps core. A fix should be easy. > > What version of 2BSD are you using? I just did this on our current >2.10BSD (soon to be released at the site near you) and didn't have any >problems. Are you using 2.9BSD? If you're on a DEC machine, or any machine that allows dereferencing of NULL pointers, it probably works fine. This is one of those long-standing problems, and is present in both BSD and System V. There are actually 2 bugs. In the -f code, the check for enough arguments left checks to see if eargc is 1 and then decrements it, exiting if it isn't, but eargc can't be 1 at that point. The -e code doesn't even check for enough arguments in System V, but I seem to remember it does the same as for -f in BSD. Here's the fix for System V (the BSD code should be similar): *** sed0.c.old --- sed0.c *************** *** 97,106 **** continue; case 'f': ! if(eargc-- <= 0) exit(2); if((fin = fopen(*++eargv, "r")) == NULL) { ! fprintf(stderr, "Cannot open pattern-file: %s\n", *eargv); exit(2); } --- 97,110 ---- continue; case 'f': ! if (eargc < 2) { ! fprintf(stderr, "-f requires a file argument\n"); ! exit(2); ! } ! eargc--; if((fin = fopen(*++eargv, "r")) == NULL) { ! perror(*eargv); exit(2); } *************** *** 109,114 **** --- 113,122 ---- continue; case 'e': + if (eargc < 2) { + fprintf(stderr, "-e requires an argument\n"); + exit(2); + } eflag++; fcomp(); eflag = 0; -- David Elliott dce@mips.com or {ames,prls,pyramid,decwrl}!mips!dce