char* comparison uses the contents, not the pointer #36

Closed
sgarceshothead opened this Issue Sep 19, 2016 · 1 comment

Projects

None yet

2 participants

@sgarceshothead
char* a = strdup("Hello");
char* b = strdup("Hello");
CHECK(a == b); // passes, even though it shouldn't

Looking at the code, it seems like 'eq' is transforming the value to a string, and then doing the comparison, which doesn't do the right thing in this particular case. Casting the pointers to void* seems to solve it.

@onqtam
Owner
onqtam commented Sep 19, 2016 edited

You're reporting this at the right time - just a day or 2 before the release of 1.1 - which is supposed to be stable - so thanks - you swayed me in the right direction.

More people would like the pointers to be compared instead of the C strings - and this is what I'll do - by default the pointers will be compared, and only if the user defines something like DOCTEST_CONFIG_COMPARE_C_STRINGS will they be treated differently.

I initially made it the way it is because boost.test does the same (I think). But I will change it for 1.1 - another little breaking change...

@onqtam onqtam added a commit that referenced this issue Sep 20, 2016
@onqtam breaking change - char pointers no longer compared as C strings by de…
…fault - you will need to define the DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING identifier to enable this! This also affects stringification of char pointers. fixes #36
e236031
@onqtam onqtam added a commit that closed this issue Sep 21, 2016
@onqtam breaking change - char pointers no longer compared as C strings by de…
…fault - you will need to define the DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING identifier to enable this! This also affects stringification of char pointers. fixes #36
c808bb0
@onqtam onqtam closed this in c808bb0 Sep 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment