Boost logo

Boost :

From: Artyom Beilis (artyom.beilis_at_[hidden])
Date: 2019-12-03 20:50:08


On Tue, Dec 3, 2019 at 4:06 PM Alexander Grund via Boost
<boost_at_[hidden]> 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().
> Makes it easy to use as one could even say `return
> _wfFoo(wstackstring(s).c_str());` w/o any checks but would be
> inconsistent with the `widen` functions which convert the passed pointer
> into a std::(w)string and hence require != NULL

I think if input is nullptr than output can be nullptr as well.

Artyom

> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


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