Minor Patches for Month

Michael Morrell morrell at hpsal2.HP.COM
Sat Nov 19 05:59:24 AEST 1988


Well, here's the first small patch for month.  Both of these changes affect
"schedule.c".  The first problem occurs when using the "G" (group post)
command.  Some machines (including 4.3 BSD) apparently dump core when you try
to fclose a file which was never opened.  The following "diff -c" output
shows the minor changes needed to take care of this.

  ---------------- Start of Fix 1 -------------------
*** schedule.c	Fri Nov 18 10:59:24 1988
--- sch.c	Fri Nov 18 09:40:37 1988
***************
*** 82,91 ****
  	alias_level = 0;
  	if (expand_aliases(names, &name_list) == -1) {
  	    print_message("too many alias levels", BELL);
! 	    if (alias_file != (FILE *)NULL)
! 		fclose(alias_file);
! 	    if (glob_alias_file != (FILE *)NULL)
! 		fclose(glob_alias_file);
  	    return;
  	}
  /*
--- 82,89 ----
  	alias_level = 0;
  	if (expand_aliases(names, &name_list) == -1) {
  	    print_message("too many alias levels", BELL);
! 	    fclose(alias_file);
! 	    fclose(glob_alias_file);
  	    return;
  	}
  /*
***************
*** 96,105 ****
  	    cur_name = cur_name->next_name;
  	}
  */
! 	if (alias_file != (FILE *)NULL)
! 	    fclose(alias_file);
! 	if (glob_alias_file != (FILE *)NULL)
! 	    fclose(glob_alias_file);
  	save_keep = keep_old;
  	keep_old = 1;
  
--- 94,101 ----
  	    cur_name = cur_name->next_name;
  	}
  */
! 	fclose(alias_file);
! 	fclose(glob_alias_file);
  	save_keep = keep_old;
  	keep_old = 1;
  ---------------- End of Fix 1 -------------------
  
The second minor change is to replace the strtok() routine I wrote with the
following one supplied with Henry Spencer's public domain stringlib package
(If I had known this existed earlier, I wouldn't have written my own).  It
seems my version dereferenced a NULL pointer, causing an error on some
machines (My only excuse is that I only realized a day or so before I
submitted the program that 4.2 BSD does not provide strtok, so I had to write
one quickly; both System 5 and 4.3 BSD provide strtok).

 -------- Replace strtok() at end of schedule.c with the following --------
/*
 * Get next token from string s (NULL on 2nd, 3rd, etc. calls),
 * where tokens are nonempty strings separated by runs of
 * chars from delim.  Writes NULs into s to end tokens.  delim need not
 * remain constant from call to call.
 */

#define C_NULL 0

static char *scanpoint = C_NULL;

char *				/* NULL if no token left */
strtok(s, delim)
char *s;
register char *delim;
{
	register char *scan;
	char *tok;
	register char *dscan;

	if (s == C_NULL && scanpoint == C_NULL)
		return(C_NULL);
	if (s != C_NULL)
		scan = s;
	else
		scan = scanpoint;

	/*
	 * Scan leading delimiters.
	 */
	for (; *scan != '\0'; scan++) {
		for (dscan = delim; *dscan != '\0'; dscan++)
			if (*scan == *dscan)
				break;
		if (*dscan == '\0')
			break;
	}
	if (*scan == '\0') {
		scanpoint = C_NULL;
		return(C_NULL);
	}

	tok = scan;

	/*
	 * Scan token.
	 */
	for (; *scan != '\0'; scan++) {
		for (dscan = delim; *dscan != '\0';)	/* ++ moved down. */
			if (*scan == *dscan++) {
				scanpoint = scan+1;
				*scan = '\0';
				return(tok);
			}
	}

	/*
	 * Reached end of string.
	 */
	scanpoint = C_NULL;
	return(tok);
}
         ----------- End of strtok() ---------------

I'm sorry if I caused any problems with these bugs.  I'll try better next time.

   Michael

P.S. I'll soon be posting a slightly revised version of monthd.c which takes
care of all the problems mentioned so far on the net and privately to me.



More information about the Comp.sources.bugs mailing list