Skip to content

Commit

Permalink
Workarounds for compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony-Nicholls authored Oct 30, 2024
1 parent 9e7ceb0 commit 60d5327
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 42 deletions.
47 changes: 31 additions & 16 deletions containers/choc_Value.h
Original file line number Diff line number Diff line change
Expand Up @@ -2319,7 +2319,11 @@ inline StringDictionary::Handle ValueView::getStringHandle() const

inline std::string_view ValueView::getString() const
{
check (stringDictionary != nullptr, "No string dictionary supplied");
// To satisfy the MSVC code analyser this check needs to be handled directly
// from this function
if (stringDictionary == nullptr)
throwError ("No string dictionary supplied");

return stringDictionary->getStringForHandle (getStringHandle());
}

Expand Down Expand Up @@ -2426,21 +2430,32 @@ void ValueView::serialise (OutputStream& output) const
if (type.isVoid())
return;

auto dataSize = type.getValueDataSize();

if (stringDictionary == nullptr || ! type.usesStrings())
{
output.write (data, dataSize);
return;
}

static constexpr uint32_t maximumSize = 16384;

if (dataSize > maximumSize)
throwError ("Out of local scratch space");

uint8_t localCopy[maximumSize];
std::memcpy (localCopy, data, dataSize);
auto dataSize = type.getValueDataSize();
check (dataSize > 0, "Invalid data size");

if (stringDictionary == nullptr || ! type.usesStrings())
{
output.write (data, dataSize);
return;
}

uint8_t* localCopy = nullptr;

#if _MSC_VER
__try
{
localCopy = (uint8_t*) _alloca (dataSize);
}
__except (GetExceptionCode() == STATUS_STACK_OVERFLOW)
{
throwError ("Stack overflow");
}
#else
localCopy = (uint8_t*) alloca (dataSize);
#endif

check (localCopy != nullptr, "Stack allocation failed");
std::memcpy (localCopy, data, dataSize);

static constexpr uint32_t maxStrings = 128;
uint32_t numStrings = 0, stringDataSize = 0;
Expand Down
24 changes: 0 additions & 24 deletions javascript/choc_javascript_QuickJS.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,18 +219,6 @@ static inline int clz32(unsigned int a)
#endif
}

/* WARNING: undefined if a = 0 */
static inline int clz64(uint64_t a)
{
#if _MSC_VER
unsigned long i;
_BitScanReverse64 (&i, a);
return 63 ^ i;
#else
return __builtin_clzll(a);
#endif
}

/* WARNING: undefined if a = 0 */
static inline int ctz32(unsigned int a)
{
Expand All @@ -243,18 +231,6 @@ static inline int ctz32(unsigned int a)
#endif
}

/* WARNING: undefined if a = 0 */
static inline int ctz64(uint64_t a)
{
#if _MSC_VER
unsigned long i;
_BitScanForward64 (&i, a);
return 63 ^ i;
#else
return __builtin_ctzll(a);
#endif
}

static inline uint64_t get_u64(const uint8_t *tab)
{
uint64_t v;
Expand Down
2 changes: 2 additions & 0 deletions platform/choc_DisableAllWarnings.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
#pragma GCC diagnostic ignored "-Wuse-after-free"
#pragma GCC diagnostic ignored "-Warray-bounds"
#pragma GCC diagnostic ignored "-Wvolatile"
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#pragma GCC diagnostic ignored "-Wfloat-equal"
#ifndef __MINGW32__
#pragma GCC diagnostic ignored "-Wredundant-move"
#endif
Expand Down
4 changes: 2 additions & 2 deletions platform/choc_ObjectiveCHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#ifndef CHOC_OBJC_HELPERS_HEADER_INCLUDED
#define CHOC_OBJC_HELPERS_HEADER_INCLUDED

#include "../platform/choc_Platform.h"
#include "choc_Platform.h"

#if CHOC_APPLE

Expand All @@ -28,7 +28,7 @@
#include <objc/message.h>
#include <type_traits>

#include "../platform/choc_Assert.h"
#include "choc_Assert.h"


//==============================================================================
Expand Down

0 comments on commit 60d5327

Please sign in to comment.