]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commit
mon/Monitor.h: return string instead of 'char *' from get_state_name() 103/head
authorDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Tue, 12 Mar 2013 17:21:40 +0000 (18:21 +0100)
committerDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Tue, 12 Mar 2013 17:21:40 +0000 (18:21 +0100)
commit60639ab67e221a72d6d63085547fc1fde23dcb97
tree3a92e102b246afa1b9f828e367096945d53986bd
parent34f198487f1765008e92846da52ec35271dce8ff
mon/Monitor.h: return string instead of 'char *' from get_state_name()

Return a string instead of 'char *' to avoid usage of std::string:c_str()
to return a 'char *' from get_state_name().

Returning result of c_str() from a function is dangerous since the
result gets (may) invalid after the related string object gets
destroyed or out of scope (which is the case with return). So you may
end up with garbage in this case.

Related warning from cppcheck:
 [src/mon/Monitor.h:172]: (error) Dangerous usage of c_str(). The value
 returned by c_str() is invalid after this call.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
src/mon/Monitor.h