Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2019-12-04 18:01:00


Alexander Grund wrote:

> Hi,
>
> in my work on Boost.Nowide I encountered a valid NULL string and am unsure
> how to handle it.
>
> Context: Every wrapper functions is basically implemented like:
>
> int fFOO(const char* s){
> wstackstring const ws(s); // Converts UTF-8 to wchar-buffer/string
> return _wfFoo(ws.c_str());
> }
>
> Similar functions like `std::wstring widen(string-or-const-char-ptr)` are
> provided which can be used like `return _wfFoo(widen(s).c_str());` in the
> example above.
>
> All was fine, because (IIRC) calling e.g. `fopen(NULL)` is not allowed
> anyway.
>
> However `freopen` DOES allow a NULL for the string. So now I'm left with a
> couple options and would like some opinions on them:
>
> 1. Make (w)stackstring aware of NULL input and if default constructed or
> with NULL return NULL for c_str().

This. Since (w)stackstring is an internal utility class, we should make it
behave in whatever way is most useful for the implementation, and in this
case, NULL-in-NULL-out is correct.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk