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

Don't redefine str(n)casecmp on windows unless they're missing #197

Merged
merged 1 commit into from Jul 2, 2018

Conversation

Projects
None yet
4 participants
@nmathewson
Copy link
Contributor

commented Jul 2, 2018

When we do redefine them, use inline functions instead of #define.

This fixes a latent code problem in our redefinition of these
functions, which was exposed by our refactoring: Previously, we
would #define strcasecmp after string.h was included, so nothing bad
would happen. But when we refactored, we would sometimes #define it
first, which was a problem on mingw, whose headers contain
(approximately):

inline int strcasecmp (const char *a, const char *b)
{ return _stricmp(a,b); }

Our define turned this into:
inline int _stricmp(const char *a, const char *b)
{ return _stricmp(a,b); }

And GCC would correctly infer that this function would loop forever,
rather than actually comparing anything. This caused bug 26594.

Fixes bug 26594; bug not in any released version of Tor.

Don't redefine str(n)casecmp on windows unless they're missing
When we do redefine them, use inline functions instead of #define.

This fixes a latent code problem in our redefinition of these
functions, which was exposed by our refactoring: Previously, we
would #define strcasecmp after string.h was included, so nothing bad
would happen.  But when we refactored, we would sometimes #define it
first, which was a problem on mingw, whose headers contain
(approximately):

inline int strcasecmp (const char *a, const char *b)
   { return _stricmp(a,b); }

Our define turned this into:
  inline int _stricmp(const char *a, const char *b)
    { return _stricmp(a,b); }

And GCC would correctly infer that this function would loop forever,
rather than actually comparing anything.  This caused bug 26594.

Fixes bug 26594; bug not in any released version of Tor.

@tor-bot tor-bot merged commit c8ccd02 into torproject:master Jul 2, 2018

0 of 2 checks passed

continuous-integration/appveyor/pr Waiting for AppVeyor build to complete
Details
continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
@coveralls

This comment has been minimized.

Copy link

commented Jul 2, 2018

Coverage Status

Coverage decreased (-0.02%) to 59.869% when pulling c8ccd02 on nmathewson:bug26594 into cb1a367 on torproject:master.

@gvanem

This comment has been minimized.

Copy link
Contributor

commented on c8ccd02 Jul 4, 2018

No, no:

static inline int strncasecmp(const char *a, const char *b, size_t n) {
  return strnicmp(a,b,n);
}
...
static inline int strcasecmp(const char *a, const char *b) {
  return stricmp(a,b);
}

This comment has been minimized.

Copy link
Contributor Author

replied Jul 5, 2018

Thanks! I'll use the variant with an underscore instead, though, since msdn says that the unprefixed versions are deprecated. Tried to fix this with fecb821.

This comment has been minimized.

Copy link
Contributor

replied Jul 5, 2018

Good. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.