[PATCH 4/7] log: Print truncated messages [and 1 more messages]

Ian Jackson ijackson at chiark.greenend.org.uk
Thu Jun 21 19:16:36 BST 2012

Simon Tatham writes ("Re: [PATCH 4/7] log: Print truncated messages"):
> [I tried to send this to sgo-software-discuss, but Mailman told me I
> wasn't allowed to post to it.]

It's subscriber postings only I'm afraid, to reduce spam.  Please
subscribe; if you read via the newsgroup, just turn off your mail

> Ian Jackson  <ijackson at chiark.greenend.org.uk> wrote:
> > Fix this by always putting "\n\0" at the end of buff.  That way a
> > truncated message is printed and the buffer will be cleared out for
> > the next call.
> [...]
> >  	assert(bp < MESSAGE_BUFLEN);
> >  	vsnprintf(buff+bp,MESSAGE_BUFLEN-bp,message,args);
> > +	buff[sizeof(buff)-2] = '\n';
> > +	buff[sizeof(buff)-1] = '\0';
> In the case where the line was _almost_ too long, so that vsnprintf
> wrote its own \0 to buff[sizeof(buff)-2], will this not have the
> unfortunate effect of adding a second newline?

See my updated commit message.

> (Also, if it were me I'd stick with one of MESSAGE_BUFLEN and
> sizeof(buff), rather than switching from one to the other half way
> through. I presume they're equivalent anyway, but it's more
> confusing like this.)

Because of this comment I wrote:

Ian Jackson writes ("Re: [PATCH 04/19] log: Print truncated messages"):
> I should have changed these sizeofs to MESSAGE_BUFLENs.

But in fact:

      static char buff[MESSAGE_BUFLEN+1]={0,};

So using MESSAGE_BUFLEN would be wrong.  And using sizeof() makes it
completely clear that at least that part of the code is correct
(modulo minor infelicities).


More information about the sgo-software-discuss mailing list