Browse Source

Merge pull request #468 from zrax/arrsize

Fix incorrect arrsize use
Adam Johnson 10 years ago
parent
commit
e98c5afe64
  1. 7
      Sources/Plasma/CoreLib/HeadSpin.h
  2. 4
      Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Win32/pnAceW32Dns.cpp
  3. 14
      Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp
  4. 5
      cmake/CompilerChecks.cmake
  5. 6
      cmake/check_constexpr.cpp
  6. 2
      cmake/hsCompilerSpecific.h.cmake

7
Sources/Plasma/CoreLib/HeadSpin.h

@ -238,7 +238,12 @@ inline double hsSwapEndianDouble(double dvalue)
* StrPrintf(buffer, arrsize(buffer), "%u", value);
*
***/
#define arrsize(a) (sizeof(a) / sizeof((a)[0]))
#ifdef HAVE_CONSTEXPR
template <typename _T, size_t _Sz>
constexpr size_t arrsize(_T(&)[_Sz]) { return _Sz; }
#else
# define arrsize(a) (sizeof(a) / sizeof((a)[0]))
#endif
/****************************************************************************

4
Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Win32/pnAceW32Dns.cpp

@ -102,7 +102,9 @@ static void LookupProcess (Lookup * lookup, unsigned error) {
in_addr const * const * const inAddr = (in_addr **) host.h_addr_list;
// allocate a buffer large enough to hold all the addresses
size_t count = arrsize(inAddr);
size_t count = 0;
while (inAddr[count])
++count;
plNetAddress* addrs = new plNetAddress[count];
// fill in address data

14
Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp

@ -561,20 +561,6 @@ static void INetAuthFileListRequestCallback (
msg->Send();
}
//============================================================================
static void INetCliAuthFileRequestCallback (
ENetError result,
void * param,
const wchar_t filename[],
hsStream * writer
) {
plNetCommFileDownloadMsg * msg = new plNetCommFileDownloadMsg;
msg->result = result;
msg->writer = writer;
StrCopy(msg->filename, filename, arrsize(filename));
msg->Send();
}
//============================================================================
static void INetCliGameJoinAgeRequestCallback (
ENetError result,

5
cmake/CompilerChecks.cmake

@ -58,6 +58,11 @@ try_compile(HAVE_GCC_DEPRECATED_ATTR ${PROJECT_BINARY_DIR}
COMPILE_DEFINITIONS -DTRY_GCC_ATTR
OUTPUT_VARIABLE OUTPUT)
# Look for C++11 constexpr support
try_compile(HAVE_CONSTEXPR ${PROJECT_BINARY_DIR}
${PROJECT_SOURCE_DIR}/cmake/check_constexpr.cpp
OUTPUT_VARIABLE OUTPUT)
configure_file(${PROJECT_SOURCE_DIR}/cmake/hsCompilerSpecific.h.cmake
${PROJECT_BINARY_DIR}/hsCompilerSpecific.h)
include_directories(${PROJECT_BINARY_DIR})

6
cmake/check_constexpr.cpp

@ -0,0 +1,6 @@
constexpr int foo() { return 5; }
int main(int, char **)
{
return foo();
}

2
cmake/hsCompilerSpecific.h.cmake

@ -51,4 +51,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#cmakedefine HAVE_CXX14_DEPRECATED_ATTR
#cmakedefine HAVE_GCC_DEPRECATED_ATTR
#cmakedefine HAVE_CONSTEXPR
#endif

Loading…
Cancel
Save