Subject: Re: CVS commit: basesrc
To: None <source-changes@netbsd.org>
From: Christos Zoulas <christos@zoulas.com>
List: source-changes
Date: 10/21/2000 02:16:34
In article <200010201846.VAA16064@netbsd.hut.fi>,
Allen Briggs <briggs@netbsd.org> wrote:

> Add {__,}fmtcheck(), a function specified by Bill Sommerfeld to check
> a user-supplied format string against a fallback format string to ensure
> that they will consume arguments of the same type.

Very cool. Two questions:
1. why there is a /*NOTREACHED*/ at the end of the static functions?
2. It might be nice if there was code in it to log an error, and mention
   in the man page that it sets errno to EFTYPE if there are no matches?

#include <errno.h>
#ifdef __AUDIT__
#include <err.h>
#endif

__const char *
__fmtcheck(const char *f1, const char *f2)
{
	const char	*f1p, *f2p;
	EFT		f1t, f2t;

	if (!f1) return f2;
	
	f1p = f1;
	f1t = FMTCHECK_START;
	f2p = f2;
	f2t = FMTCHECK_START;
	while ((f1t = get_next_format(&f1p, f1t)) != FMTCHECK_DONE) {
		if (f1t == FMTCHECK_UNKNOWN)
			goto bad;
		f2t = get_next_format(&f2p, f2t);
		if (f1t != f2t)
			goto bad;
	}
	return f1;
bad:
	errno = EFTYPE;
#ifdef __AUDIT__
	warn("Mismatched user format string `%s', does not match with `%s' ",
	    f1, f2);
#endif
	return f2;
}

christos