Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

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

sgarceshothead opened this issue Sep 19, 2016 · 1 comment

Comments

@sgarceshothead
Copy link

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
Copy link
Member

onqtam commented Sep 19, 2016

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 added a commit that referenced this issue Sep 20, 2016
…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
@onqtam onqtam closed this as completed in c808bb0 Sep 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants