Date: Sat, 18 Nov 2000 10:02:08 +0200 From: "Eli Zaretskii" Sender: halo1 AT zahav DOT net DOT il To: Richard Dawe Message-Id: <2950-Sat18Nov2000100207+0200-eliz@is.elta.co.il> X-Mailer: Emacs 20.6 (via feedmail 8.3.emacs20_6 I) and Blat ver 1.8.6 CC: djgpp-workers AT delorie DOT com In-reply-to: <3A132065.9FA6E06B@bigfoot.com> (message from Richard Dawe on Wed, 15 Nov 2000 23:46:45 +0000) Subject: Re: snprintf() diff, take 2 References: <3A132065 DOT 9FA6E06B AT bigfoot DOT com> Reply-To: djgpp-workers AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp-workers AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk [Sorry for a long delay, I'm very busy these days.] > Date: Wed, 15 Nov 2000 23:46:45 +0000 > From: Richard Dawe > > * I added a note on the maximum value of 'n' for snprintf(), vsnprintf(). > The value of errno is not documented, since errno is only set for the case > where n is too big. This seems to be OK according to the C spec - we can > set errno to whatever we like, since snprintf() does not have a defined > effect on errno. Nevertheless, I think we should document what value does our implementation put into errno, when it does. > + _strbuf._flag = _IOWRT | _IOSTRG | _IONTERM; > + _strbuf._ptr = str; > + _strbuf._cnt = n - 1; > + len = _doprnt(fmt, &(fmt)+1, &_strbuf); > + if (n != 0) > + *_strbuf._ptr = 0; > + return len; This doesn't seem to handle the case where N is zero. In this case, STR may or may not be a NULL (if it is, I think _doprnt will bomb, at least for some formats, like %c; or am I missing something?), and we still need to return ``the number of characters that would have been written had N been sufficiently large'', to quote from C9x. > + @port-note ansi For DJGPP, the maximum accepted value of @var{n} is > INT_MAX. An error is returned if @var{n} is greater than this limit. Please use @code{INT_MAX}, and I think it would be a good idea to say that it is defined in . Also, please leave two blanks after the dots which end statements. > + @portability ansi > \ No newline at end of file Please add the missing newline. > *** /develop/djgpp/tests/libc/ansi/stdio/snprintf.c Sun Nov 12 21:57:18 2000 > --- /develop/djgpp.dev/tests/libc/ansi/stdio/snprintf.c Wed Nov 15 22:41:26 2000 This doesn't test the special cases of a NULL pointer STR argument, zero N argument (with or without STR == NULL), and the case where ``an encoding error'' happens (which I understand as an invalid format specifier, or something else that causes _doprnt to return -1). I think we want at least some of these cases in the test suite, to make sure the implementation is working as expected.