Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!rutgers!ucla-cs!zen!ucbvax!decvax!ima!haddock!karl From: karl@haddock.ISC.COM (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: Passing NULLs to printf Message-ID: <846@haddock.ISC.COM> Date: Fri, 31-Jul-87 19:48:25 EDT Article-I.D.: haddock.846 Posted: Fri Jul 31 19:48:25 1987 Date-Received: Sun, 2-Aug-87 04:49:53 EDT References: <1407@cullvax.UUCP> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Boston Lines: 16 In article <1407@cullvax.UUCP> drw@cullvax.UUCP (Dale Worley) writes: >But, suppose we write: > printf("%.0s", (char *)NULL) >This should print zero characters out of the string, and so won't >actually reference any character through the null pointer. I seem to remember noticing once that one implementation of strncpy would test for a terminating NUL *before* testing the counter, thus when no NUL was present it would fetch an extra byte. Completely harmless, unless you happened to be at the end of readable memory! It would be nice if this were guaranteed not to happen (in printf as well as in the strnXXX family). In particular I agree it should be legal to grab zero characters from a NULL pointer, e.g. the result of [ANSI] malloc(0). Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint