Skip to content

Commit

Permalink
0.10 fix for crashes on OSX 10.6
Browse files Browse the repository at this point in the history
strnlen is available at build-time but not at runtime, causing a crash.

0.11 drops support for 10.6, so this is not needed in master.
  • Loading branch information
theuni committed Mar 19, 2015
1 parent 601327b commit 8752b5c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
4 changes: 1 addition & 3 deletions src/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ typedef u_int SOCKET;
#define THREAD_PRIORITY_ABOVE_NORMAL (-2)
#endif

#if HAVE_DECL_STRNLEN == 0
size_t strnlen( const char *start, size_t max_len);
#endif // HAVE_DECL_STRNLEN
size_t strnlen_int( const char *start, size_t max_len);

#endif // BITCOIN_COMPAT_H
7 changes: 3 additions & 4 deletions src/compat/strnlen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
#endif

#include <cstring>

#if HAVE_DECL_STRNLEN == 0
size_t strnlen( const char *start, size_t max_len)
// OSX 10.6 is missing strnlen at runtime, but builds targetting it will still
// succeed. Define our own version here to avoid a crash.
size_t strnlen_int( const char *start, size_t max_len)
{
const char *end = (const char *)memchr(start, '\0', max_len);

return end ? (size_t)(end - start) : max_len;
}
#endif // HAVE_DECL_STRNLEN
2 changes: 1 addition & 1 deletion src/protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ CMessageHeader::CMessageHeader(const char* pszCommand, unsigned int nMessageSize

std::string CMessageHeader::GetCommand() const
{
return std::string(pchCommand, pchCommand + strnlen(pchCommand, COMMAND_SIZE));
return std::string(pchCommand, pchCommand + strnlen_int(pchCommand, COMMAND_SIZE));
}

bool CMessageHeader::IsValid() const
Expand Down

0 comments on commit 8752b5c

Please sign in to comment.