[net.news.b] news 2.10 readr.c bug fixes

geoff (05/18/83)

I've fixed three bugs in readr.c of news 2.10.  Our news feed has been
sluggish lately, so I hope this doesn't duplicate earlier bug reports
that I haven't seen yet.

First, some systems don't have a /usr/tmp because it is a nuisance to
have two publically writable directories to clear out periodically and
/tmp is a file system of adequate size.  readr.c has the directory name
/usr/tmp wired-in and this will need to be changed for such systems.
Since /tmp makes more sense than /usr/tmp, I've just changed /usr/tmp
to /tmp.  Others may want to make the directory name a defined constant
in defs.h or the makefile.

14c14
< char *tft = "/usr/tmp/folXXXXXX";
---
> char *tft = "/tmp/folXXXXXX";

Second, readr.c fails to test the value returned by fopen when using
the template tft.  This aggravates the first bug on systems with no
/usr/tmp but is a bad practice in any case, since even on systems with
a /usr/tmp, a fopen for a file in /usr/tmp could fail due to kernel
table exhaustion, an existing file of the same name with no permission,
etc.

671,675c671,678
< 		tfp = fopen(tf, "w");
< 		fprintf(tfp, "To: %s\n", pathptr);
< 		fprintf(tfp, "Subject: %s\n", subj);
< 		fprintf(tfp, "References: %s\n\n", folbuf);
< 		fclose(tfp);
---
> 		if ((tfp = fopen(tf, "w")) == NULL)
> 			perror(tf);
> 		else {
> 			fprintf(tfp, "To: %s\n", pathptr);
> 			fprintf(tfp, "Subject: %s\n", subj);
> 			fprintf(tfp, "References: %s\n\n", folbuf);
> 			fclose(tfp);
> 		}
860,867c863,875
< 		tfp = fopen(tf, "w");
< 		if (edit) {
< 			fprintf(tfp, "Newsgroups: %s\n", ng);
< 			fprintf(tfp, "Subject: %s\n", subj);
< 			fprintf(tfp, "References: %s\n", folbuf);
< 			if (hptr->keywords[0])
< 				fprintf(tfp, "Keywords: %s\n", hptr->keywords);
< 			fprintf(tfp, "\n");
---
> 		if ((tfp = fopen(tf, "w")) == NULL)
> 			perror(tf);
> 		else {
> 			if (edit) {
> 				fprintf(tfp, "Newsgroups: %s\n", ng);
> 				fprintf(tfp, "Subject: %s\n", subj);
> 				fprintf(tfp, "References: %s\n", folbuf);
> 				if (hptr->keywords[0])
> 					fprintf(tfp, "Keywords: %s\n",
> 						hptr->keywords);
> 				fprintf(tfp, "\n");
> 			}
> 			fclose(tfp);
869d876
< 		fclose(tfp);

Third, pngsize is long, yet readr.c twice prints it via %d instead of
%ld.  Would people coding on VAXen please distinguish between ints and
longs? They aren't the same everywhere.

1128c1135
< 			fprintf(ofp, "%d\n", pngsize);
---
> 			fprintf(ofp, "%ld\n", pngsize);
1130c1137
< 			fprintf(ofp, "%d-%d\n", bit, pngsize);
---
> 			fprintf(ofp, "%d-%ld\n", bit, pngsize);

Geoff Collyer, U. of Toronto