Boost logo

Boost :

Subject: Re: [boost] [system] A non-allocating message() overload
From: Peter Dimov (lists_at_[hidden])
Date: 2018-09-20 11:51:43

> charleyb123 wrote:
> > Question: Is there a *guarantee* that 'message()' never return
> > 'nullptr'? (Is that ever desired?)
> The only failure mode would be when the function needs to compose a
> message and the provided buffer is too small to hold it; I'll have to
> check what strerror_r(12345, buffer, 1) (for instance) does but in my
> opinion nullptr should not be a valid return value; in this case something
> like truncation or returning "Insufficient buffer size for message" would
> be my preference.

On reflection, I take that back. nullptr will be a valid return value, but
only in the case where you pass nullptr as the buffer (and, accordingly, 0
as the length.)

That is, the function should not "fail" with "Insufficient buffer size for
message", it will just fill the buffer and truncate, even when the buffer
size is something ridiculously small such as 2, 1, or even 0.

This enables the (apparently idiomatic when using strerror_r) technique of
using `message( ev, nullptr, 0 )` to detect whether the message is static,
and do something else if it isn't.

Boost list run by bdawes at, gregod at, cpdaniel at, john at