Ö
Öö Tiib
char* CstringGive ()
Error! I see 'char*' my rules suggested against raw pointers.
{
::cmw::marshalling_integer slen(*this);
::std::unique_ptr<char[]> cstr:new char[slen.value + 1]);
You should not use smart pointers for dynamic arrays. Use std::vector
or std::string. Smart pointer does 'delete', not 'delete[]' and so
you result with undefined behavior.
This page --
http://en.cppreference.com/w/cpp/memory/unique_ptr
-- says,
"There are two versions of std::unique_ptr:
1) Manages the lifetime of a single object (e.g. allocated with new)
2) Manages the lifetime of a dynamically-allocated array of objects (e.g.allocated with new[])"
Ok, I stand corrected. Still I suggested to use std::vector
(or std::string) instead. Those have some immediately useful additional
data and member functions.
You also said,
"Never dereference a pointer without comparing it with
'nullptr' first."
Do you object to this line:
::cmw::marshalling_integer slen(*this);
?
No. 'this' is not pointer variable. It is keyword that resolves into
rvalue pointer that may never be 'nullptr'. It is not a reference
only because it was added into language before references.
See http://www.stroustrup.com/bs_faq2.html#this
When 'this' somehow is 'nullptr' then some undefined behavior is
already in effect.