wovo / hwlib

C++ OO micro-controller library for close-to-the-hardware programming
Boost Software License 1.0
58 stars 26 forks source link

fixing compare by ending which had a faulty end checker #12

Closed CvRXX closed 6 years ago

CvRXX commented 6 years ago

The == of the hwlib::string would never find a '\0' in his own string so I changed it to check for the end pointer.

cjsmeele commented 6 years ago

AIUI, end() may point to unallocated memory when the string is not constructed from a null-terminated string. As such dereferencing it is probably a bad idea.

I would suggest checking the content lengths of each string and leaving the rest of the comparison function unchanged from @ManDeJan's version. (edit: nvm, must work with const char* as rhs too, and checking the length would be unnecessarily expensive)

CvRXX commented 6 years ago

Thanks, I fixed it by comparing pointers instead of values. @cjsmeele could you confirm that this is correct?

cjsmeele commented 6 years ago

Can't test it but it looks good to me :-)

CvRXX commented 6 years ago

Wouter fixed it :-p