Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site umcp-cs.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!godot!harvard!seismo!umcp-cs!chris From: chris@umcp-cs.UUCP (Chris Torek) Newsgroups: net.sources.bugs Subject: patches for patch Message-ID: <1338@umcp-cs.UUCP> Date: Sun, 25-Nov-84 02:24:58 EST Article-I.D.: umcp-cs.1338 Posted: Sun Nov 25 02:24:58 1984 Date-Received: Mon, 26-Nov-84 02:03:07 EST Distribution: net Organization: U of Maryland, Computer Science Dept., College Park, MD Lines: 800 "patch" looks like a useful program. However, try running "lint" on it . . . ! Here's a patch to make it pass lint (with one warning about a "possible pointer alignment problem" from a typecast on malloc; big deal). I don't claim it's any less buggy; I didn't make any real substantive changes. RCS file: RCS/patch.c,v retrieving revision 1.1 diff -c1 -r1.1 patch.c *** /tmp/,RCSt1022548 Sun Nov 25 02:19:48 1984 --- patch.c Sun Nov 25 02:19:42 1984 *************** *** 59,60 char buf[MAXLINELEN]; /* general purpose buffer */ --- 59,61 ----- + char serrbuf[BUFSIZ]; /* buffer for stderr */ char buf[MAXLINELEN]; /* general purpose buffer */ *************** *** 102,103 char *strcpy(); int my_exit(); --- 103,106 ----- char *strcpy(); + char *strcat(); + char *sprintf(); /* usually */ int my_exit(); *************** *** 105,106 char *fetchname(); --- 108,112 ----- char *fetchname(); + long atol(); + long lseek(); + char *mktemp(); *************** *** 113,115 LINENUM patch_first(); ! int patch_lines(); char patch_char(); --- 119,121 ----- LINENUM patch_first(); ! LINENUM patch_lines(); char patch_char(); *************** *** 133,135 ! setbuf(stderr,malloc(BUFSIZ)); for (i = 0; i 0) ! write(1,buf,i); ! close(fromfd); return; --- 519,523 ----- while ((i=read(fromfd,buf,sizeof buf)) > 0) ! if (write(1,buf,i) != 1) ! fatal("patch: write failed\n"); ! (void)close(fromfd); return; *************** *** 519,522 ! strcpy(bakname,to); ! strcat(bakname,origext?origext:ORIGEXT); if (stat(to,&filestat) >= 0) { /* output file exists */ --- 525,528 ----- ! (void)strcpy(bakname,to); ! (void)strcat(bakname,origext?origext:ORIGEXT); if (stat(to,&filestat) >= 0) { /* output file exists */ *************** *** 537,539 else ! strcpy(simplename, simplename+1); } --- 543,545 ----- else ! (void)strcpy(simplename, simplename+1); } *************** *** 568,572 while ((i=read(fromfd,buf,sizeof buf)) > 0) ! write(tofd,buf,i); ! close(fromfd); ! close(tofd); } --- 574,579 ----- while ((i=read(fromfd,buf,sizeof buf)) > 0) ! if (write(tofd,buf,i) != i) ! fatal("patch: write failed\n"); ! (void)close(fromfd); ! (void)close(tofd); } *************** *** 572,574 } ! unlink(from); } --- 579,581 ----- } ! (void)unlink(from); } *************** *** 576,577 copy_file(from,to) { --- 583,585 ----- copy_file(from,to) + char *from, *to; { *************** *** 588,592 while ((i=read(fromfd,buf,sizeof buf)) > 0) ! write(tofd,buf,i); ! close(fromfd); ! close(tofd); } --- 596,601 ----- while ((i=read(fromfd,buf,sizeof buf)) > 0) ! if (write(tofd,buf,i) != i) ! fatal("patch: write (%s) failed\n", to); ! (void)close(fromfd); ! (void)close(tofd); } *************** *** 606,608 copy_till(input_lines); /* dump remainder of file */ ! fclose(ofp); ofp = Nullfp; --- 615,617 ----- copy_till(input_lines); /* dump remainder of file */ ! (void)fclose(ofp); ofp = Nullfp; *************** *** 625,627 { ! register int pline; register LINENUM iline; --- 634,636 ----- { ! register LINENUM pline; register LINENUM iline; *************** *** 627,629 register LINENUM iline; ! register int pat_lines = patch_lines(); --- 636,638 ----- register LINENUM iline; ! register LINENUM pat_lines = patch_lines(); *************** *** 655,657 i_size = 0; ! free(i_ptr); free(i_womp); --- 664,666 ----- i_size = 0; ! free((char *)i_ptr); free(i_womp); *************** *** 662,664 using_plan_a = TRUE; /* maybe the next one is smaller */ ! close(tifd); tifd = -1; --- 671,673 ----- using_plan_a = TRUE; /* maybe the next one is smaller */ ! (void)close(tifd); tifd = -1; *************** *** 692,694 if (stat(filename,&filestat) < 0) { ! sprintf(buf,"RCS/%s%s",filename,RCSSUFFIX); if (stat(buf,&filestat) >= 0 || stat(buf+4,&filestat) >= 0) { --- 701,703 ----- if (stat(filename,&filestat) < 0) { ! (void)sprintf(buf,"RCS/%s%s",filename,RCSSUFFIX); if (stat(buf,&filestat) >= 0 || stat(buf+4,&filestat) >= 0) { *************** *** 694,696 if (stat(buf,&filestat) >= 0 || stat(buf+4,&filestat) >= 0) { ! sprintf(buf,CHECKOUT,filename); if (verbose) --- 703,705 ----- if (stat(buf,&filestat) >= 0 || stat(buf+4,&filestat) >= 0) { ! (void)sprintf(buf,CHECKOUT,filename); if (verbose) *************** *** 702,704 else { ! sprintf(buf,"%s%s",SCCSPREFIX,filename); if (stat(buf,&filestat) >= 0) { --- 711,713 ----- else { ! (void)sprintf(buf,"%s%s",SCCSPREFIX,filename); if (stat(buf,&filestat) >= 0) { *************** *** 704,706 if (stat(buf,&filestat) >= 0) { ! sprintf(buf,GET,filename); if (verbose) --- 713,715 ----- if (stat(buf,&filestat) >= 0) { ! (void)sprintf(buf,GET,filename); if (verbose) *************** *** 716,718 i_size = filestat.st_size; ! i_womp = malloc(i_size+2); if (i_womp == Nullch) --- 725,727 ----- i_size = filestat.st_size; ! i_womp = malloc((unsigned)(i_size+2)); if (i_womp == Nullch) *************** *** 721,723 fatal("Can't open file %s\n",filename); ! if (read(ifd,i_womp,i_size) < i_size) fatal("Can't read file %s\n",filename); --- 730,732 ----- fatal("Can't open file %s\n",filename); ! if (read(ifd,i_womp,(int)i_size) < i_size)/* but what if i_size>32767? */ fatal("Can't read file %s\n",filename); *************** *** 723,725 fatal("Can't read file %s\n",filename); ! close(ifd); if (i_womp[i_size-1] != '\n') --- 732,734 ----- fatal("Can't read file %s\n",filename); ! (void)close(ifd); if (i_womp[i_size-1] != '\n') *************** *** 735,737 } ! i_ptr = (char **)malloc((iline + 1) * sizeof(char *)); if (i_ptr == Null(char **)) { /* shucks, it was a near thing */ --- 744,746 ----- } ! i_ptr = (char **)malloc((unsigned)((iline + 1) * sizeof(char *))); if (i_ptr == Null(char **)) { /* shucks, it was a near thing */ *************** *** 737,739 if (i_ptr == Null(char **)) { /* shucks, it was a near thing */ ! free(i_womp); return FALSE; --- 746,748 ----- if (i_ptr == Null(char **)) { /* shucks, it was a near thing */ ! free((char *)i_womp); return FALSE; *************** *** 780,782 fatal("Can't open file %s\n",filename); ! mktemp(TMPINNAME); if ((tifd = creat(TMPINNAME,0666)) < 0) --- 789,791 ----- fatal("Can't open file %s\n",filename); ! (void)mktemp(TMPINNAME); if ((tifd = creat(TMPINNAME,0666)) < 0) *************** *** 800,802 } ! fseek(ifp,0L,0); /* rewind file */ lines_per_buf = BUFFERSIZE / maxlen; --- 809,811 ----- } ! (void)fseek(ifp,0L,0); /* rewind file */ lines_per_buf = BUFFERSIZE / maxlen; *************** *** 803,806 tireclen = maxlen; ! tibuf[0] = malloc(BUFFERSIZE + 1); ! tibuf[1] = malloc(BUFFERSIZE + 1); if (tibuf[1] == Nullch) --- 812,815 ----- tireclen = maxlen; ! tibuf[0] = malloc((unsigned)(BUFFERSIZE + 1)); ! tibuf[1] = malloc((unsigned)(BUFFERSIZE + 1)); if (tibuf[1] == Nullch) *************** *** 809,811 if (! (i % lines_per_buf)) /* new block */ ! write(tifd,tibuf[0],BUFFERSIZE); if (fgets(tibuf[0] + maxlen * (i%lines_per_buf), maxlen + 1, ifp) --- 818,820 ----- if (! (i % lines_per_buf)) /* new block */ ! (void)write(tifd,tibuf[0],BUFFERSIZE); if (fgets(tibuf[0] + maxlen * (i%lines_per_buf), maxlen + 1, ifp) *************** *** 814,816 if (i % lines_per_buf) ! write(tifd,tibuf[0],BUFFERSIZE); break; --- 823,825 ----- if (i % lines_per_buf) ! (void)write(tifd,tibuf[0],BUFFERSIZE); break; *************** *** 818,821 } ! fclose(ifp); ! close(tifd); if ((tifd = open(TMPINNAME,0)) < 0) { --- 827,830 ----- } ! (void)fclose(ifp); ! (void)close(tifd); if ((tifd = open(TMPINNAME,0)) < 0) { *************** *** 845,847 tiline[whichbuf] = baseline; ! lseek(tifd,(long)baseline / lines_per_buf * BUFFERSIZE,0); if (read(tifd,tibuf[whichbuf],BUFFERSIZE) < 0) --- 854,856 ----- tiline[whichbuf] = baseline; ! (void)lseek(tifd,(long)baseline / lines_per_buf * BUFFERSIZE,0); if (read(tifd,tibuf[whichbuf],BUFFERSIZE) < 0) *************** *** 882,884 if (filename == Nullch || !*filename || strEQ(filename,"-")) { ! mktemp(TMPPATNAME); pfp = fopen(TMPPATNAME,"w"); --- 891,893 ----- if (filename == Nullch || !*filename || strEQ(filename,"-")) { ! (void)mktemp(TMPPATNAME); pfp = fopen(TMPPATNAME,"w"); *************** *** 888,890 fputs(buf,pfp); ! fclose(pfp); filename = TMPPATNAME; --- 897,899 ----- fputs(buf,pfp); ! (void)fclose(pfp); filename = TMPPATNAME; *************** *** 894,896 fatal("patch file %s not found\n",filename); ! fstat(pfp->_file,&filestat); p_filesize = filestat.st_size; --- 903,905 ----- fatal("patch file %s not found\n",filename); ! (void)fstat(pfp->_file,&filestat); p_filesize = filestat.st_size; *************** *** 953,955 register char *s, *t; - char *ret; char *oldname = Nullch; --- 962,963 ----- register char *s, *t; char *oldname = Nullch; *************** *** 958,960 ! fseek(pfp,p_base,0); for (;;) { --- 966,968 ----- ! (void)fseek(pfp,p_base,0); for (;;) { *************** *** 1050,1053 register char *t; ! char *test; ! char tmpbuf[64]; --- 1058,1060 ----- register char *t; ! char tmpbuf[200]; *************** *** 1060,1062 name = savestr(name); ! sprintf(tmpbuf,"RCS/%s",name); free(s); --- 1067,1069 ----- name = savestr(name); ! (void)sprintf(tmpbuf,"RCS/%s",name); free(s); *************** *** 1063,1065 if (stat(name,&filestat) < 0) { ! strcat(tmpbuf,RCSSUFFIX); if (stat(tmpbuf,&filestat) < 0 && stat(tmpbuf+4,&filestat) < 0) { --- 1070,1072 ----- if (stat(name,&filestat) < 0) { ! (void)strcat(tmpbuf,RCSSUFFIX); if (stat(tmpbuf,&filestat) < 0 && stat(tmpbuf+4,&filestat) < 0) { *************** *** 1065,1067 if (stat(tmpbuf,&filestat) < 0 && stat(tmpbuf+4,&filestat) < 0) { ! sprintf(tmpbuf,"%s%s",SCCSPREFIX,name); if (stat(tmpbuf,&filestat) < 0) { --- 1072,1074 ----- if (stat(tmpbuf,&filestat) < 0 && stat(tmpbuf+4,&filestat) < 0) { ! (void)sprintf(tmpbuf,"%s%s",SCCSPREFIX,name); if (stat(tmpbuf,&filestat) < 0) { *************** *** 1088,1090 if (verbose && p_base < file_pos) { ! fseek(pfp,p_base,0); say("The text leading up to this was:\n--------------------------\n"); --- 1095,1097 ----- if (verbose && p_base < file_pos) { ! (void)fseek(pfp,p_base,0); say("The text leading up to this was:\n--------------------------\n"); *************** *** 1097,1099 else ! fseek(pfp,file_pos,0); } --- 1104,1106 ----- else ! (void)fseek(pfp,file_pos,0); } *************** *** 1126,1128 if (p_max - p_last < 4) ! strcpy(buf," \n"); /* assume blank lines got chopped */ else --- 1133,1135 ----- if (p_max - p_last < 4) ! (void)strcpy(buf," \n"); /* assume blank lines got chopped */ else *************** *** 1232,1234 } ! sprintf(buf,"*** %d,%d\n", p_first, p_first + p_lines - 1); p_line[0] = savestr(buf); --- 1239,1241 ----- } ! (void)sprintf(buf,"*** %d,%d\n", p_first, p_first + p_lines - 1); p_line[0] = savestr(buf); *************** *** 1256,1258 } ! sprintf(buf,"--- %d,%d\n",min,max); p_line[i] = savestr(buf); --- 1263,1265 ----- } ! (void)sprintf(buf,"--- %d,%d\n",min,max); p_line[i] = savestr(buf); *************** *** 1307,1309 if (buf != s) ! strcpy(buf,s); } --- 1314,1316 ----- if (buf != s) ! (void)strcpy(buf,s); } *************** *** 1318,1319 patch_lines() --- 1325,1327 ----- + LINENUM patch_lines() *************** *** 1359,1362 char * ! savestr(string) ! char *string; { --- 1367,1370 ----- char * ! savestr(s) ! register char *s; { *************** *** 1362,1364 { ! return strcpy(malloc(strlen(string)+1),string); } --- 1370,1382 ----- { ! register char *rv, ! *t; ! ! t = s; ! while (*t++); ! rv = malloc ((unsigned) (t - s)); ! if (rv == NULL) ! fatal ("patch: out of memory (savestr)\n"); ! t = rv; ! while (*t++ = *s++); ! return rv; } *************** *** 1368,1373 { ! unlink(TMPINNAME); ! unlink(TMPOUTNAME); ! unlink(TMPREJNAME); ! unlink(TMPPATNAME); exit(status); --- 1386,1391 ----- { ! (void)unlink(TMPINNAME); ! (void)unlink(TMPOUTNAME); ! (void)unlink(TMPREJNAME); ! (void)unlink(TMPPATNAME); exit(status); *************** *** 1375,1376 say(pat,arg1,arg2,arg3) --- 1393,1405 ----- + #ifdef lint + + /*VARARGS ARGSUSED*/ + say(pat) char *pat; { ; } + /*VARARGS ARGSUSED*/ + fatal(pat) char *pat; { ; } + /*VARARGS ARGSUSED*/ + ask(pat) char *pat; { ; } + + #else lint + say(pat,arg1,arg2,arg3) *************** *** 1380,1382 fprintf(stderr,pat,arg1,arg2,arg3); ! fflush(stderr); } --- 1409,1411 ----- fprintf(stderr,pat,arg1,arg2,arg3); ! (void)fflush(stderr); } *************** *** 1396,1397 int ttyfd = open("/dev/tty",2); --- 1425,1427 ----- int ttyfd = open("/dev/tty",2); + int r; *************** *** 1398,1401 say(pat,arg1,arg2,arg3); ! read((ttyfd < 0 ? 2 : ttyfd), buf, sizeof buf); ! close(ttyfd); } --- 1428,1437 ----- say(pat,arg1,arg2,arg3); ! if (ttyfd >= 0) { ! r = read(ttyfd, buf, sizeof buf); ! (void)close(ttyfd); ! } ! else ! r = read(2, buf, sizeof buf); ! if (r <= 0) ! buf[0] = 0; } *************** *** 1401,1402 } --- 1437,1439 ----- } + #endif lint *************** *** 1423,1426 { ! signal(SIGHUP,my_exit); ! signal(SIGINT,my_exit); } --- 1460,1465 ----- { ! if (signal(SIGHUP, SIG_IGN) != SIG_IGN) ! (void) signal(SIGHUP, my_exit); ! if (signal(SIGINT, SIG_IGN) != SIG_IGN) ! (void) signal(SIGINT, my_exit); } *************** *** 1429,1432 { ! signal(SIGHUP, SIG_IGN); ! signal(SIGINT, SIG_IGN); } --- 1468,1471 ----- { ! (void) signal(SIGHUP, SIG_IGN); ! (void) signal(SIGINT, SIG_IGN); } -- (This line accidently left nonblank.) In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (301) 454-7690 UUCP: {seismo,allegra,brl-bmd}!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris@maryland