173 reputation
7
bio website
location
age 50
visits member for 1 year, 7 months
seen Apr 6 at 9:30

Hi!


Apr
16
awarded  Popular Question
Dec
14
awarded  Scholar
Dec
14
accepted How to best protect from 0 passed to std::string parameters?
Dec
13
awarded  Editor
Dec
13
revised How to best protect from 0 passed to std::string parameters?
added 219 characters in body
Dec
13
comment How to best protect from 0 passed to std::string parameters?
yes I should have made it const string& s, I forgot actually. But even so, aren't I still vulnerable to undefined behaviour? The caller can still pass a 0, right?
Dec
13
awarded  Nice Question
Dec
9
comment How to best protect from 0 passed to std::string parameters?
@user1158692 You're right I should take a const string& there unless there's a reason not to, which this snippet doesn't have.
Dec
8
comment How to best protect from 0 passed to std::string parameters?
@ratchetfreak In a way I think that's the answer I was looking for. So basically I have to protect myself.
Dec
8
comment How to best protect from 0 passed to std::string parameters?
@vy32 Some of the code I write that accepts std::string goes into libraries used by other projects where I am not the caller. I am looking for a way to gracefully handle the situation and inform the caller (maybe with an exception) that they passed an incorrect argument without crashing the program. (OK, granted, the caller might not handle an exception I throw and the program will crash anyway.)
Dec
8
comment How to best protect from 0 passed to std::string parameters?
@ratchetfreak Sorry I misunderstood.
Dec
8
comment How to best protect from 0 passed to std::string parameters?
@ratchetfreak I didn't know that char* s = 0 is undefined. I've seen it at least a few hundred times in my life (usually in the form of char* s = NULL). Do you have a reference to back that up?
Dec
8
awarded  Student
Dec
8
comment How to best protect from 0 passed to std::string parameters?
I think the problem would start even before I could call c_str(). I read (but don't have handy) that the initialization of std::string with 0 leads to undefined behaviour.
Dec
8
asked How to best protect from 0 passed to std::string parameters?
Nov
6
awarded  Quorum
Sep
3
awarded  Supporter