www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2000/11/10/04:17:44

Date: Fri, 10 Nov 2000 11:18:20 +0200
From: "Eli Zaretskii" <eliz AT is DOT elta DOT co DOT il>
Sender: halo1 AT zahav DOT net DOT il
To: Richard Dawe <richdawe AT bigfoot DOT com>
Message-Id: <7458-Fri10Nov2000111820+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: <3A0B329F.D33F7737@bigfoot.com> (message from Richard Dawe on
Thu, 09 Nov 2000 23:26:23 +0000)
Subject: Re: Summary of the snprintf() situation
References: <3A09EAB9 DOT 6924045A AT bigfoot DOT com> <3A0B329F DOT D33F7737 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

> Date: Thu, 09 Nov 2000 23:26:23 +0000
> From: Richard Dawe <richdawe AT bigfoot DOT com>

It's been a long time since that discussion, and I have a bad habit of
forgetting minor details, so please take what I say below with a grain
of salt.

> Richard Dawe wrote:
> > static __inline__ int __putc_raw(int const x,FILE *const p)
> > {
> >    if(p->_cnt>0)
> >    {
> >       p->_cnt--;
> >       return((unsigned char)(*(p->_ptr++)=(unsigned char)x));
> >    } else if (p->_flag & _IOSTR)
> >    {
> >       /* For String stream never flush.  And we also mimic the
> >        * GNU libc by keep on counting.
> >        */
> >       p->cnt--;
> >       return 0;
> >    }
> >    return(_flsbuf(x,p));
> > }
[snip]
> > Why do we need to get to negative values of _cnt at all?  We could
> > simply leave alone the _cnt member of the FILE object for _IOSTRG
> > ``streams''.
> 
> I have to admit, reading this again, I am confused by what you say, Eli.
> If you don't track the position in the buffer using _cnt, what do you use?

p->_cnt is not used for tracking the position, it is only used to know
how much more free space do we have in p->_buf.  To track the buffer
position, we use p->_ptr; see the code above.

> Maybe I have an idea that will work. The intention of returning EOF is to
> stop _cnt wrapping round.

I think that returning EOF should be a sign of some error.  What error
do we have here, that we need EOF?

>  _cnt is an int, whereas snprintf()'s buffer size
> is a size_t. Firstly, change _cnt to a ssize_t. Then place a restriction
> on the maximum buffer size, namely the maximum (positive) number that can
> be stored in both a size_t and ssize_t. Now, what error to return, when
> the buffer size is bigger than this?

Are you trying to solve the problem of the argument n being too large?
If so, how does this relate to _cnt being negative?

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019