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

Code analysis issues #1476

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ class UnityPeer final : public ComponentPeer,
//==============================================================================
void setMinimised (bool) override {}
bool isMinimised() const override { return false; }
bool isShowing() const override { return true; }
void setFullScreen (bool) override {}
bool isFullScreen() const override { return false; }
bool setAlwaysOnTop (bool) override { return false; }
Expand Down
4 changes: 3 additions & 1 deletion modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ void MidiKeyboardComponent::updateNoteUnderMouse (Point<float> pos, bool isDown,
const auto newNote = noteInfo.note;
const auto oldNote = mouseOverNotes.getUnchecked (fingerNum);
const auto oldNoteDown = mouseDownNotes.getUnchecked (fingerNum);
const auto eventVelocity = useMousePositionForVelocity ? noteInfo.velocity * velocity : velocity;
// SURGE PATCH: Don't double scale velocity
const auto eventVelocity = useMousePositionForVelocity ? noteInfo.velocity /* * velocity */ : velocity;
// END SURGE PATCH

if (oldNote != newNote)
{
Expand Down
2 changes: 1 addition & 1 deletion modules/juce_core/javascript/choc/containers/choc_Value.h
Original file line number Diff line number Diff line change
Expand Up @@ -2838,7 +2838,7 @@ inline void Value::changeMember (uint32_t index, const Type& newType, void* newD

for (uint32_t i = 0; i < numElements; ++i)
{
auto member = value.type.getObjectMember (i);
const auto &member = value.type.getObjectMember (i);
newCopy.addMember (member.name, i == index ? ValueView (newType, newData, newDictionary) : value[i]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6023,8 +6023,8 @@ static int compute_stack_size(const uint8_t *bc_buf, int bc_buf_len)
pos = 0;
while (pos < bc_buf_len) {
opcode = bc_buf[pos];
len = reopcode_info[opcode].size;
assert(opcode < REOP_COUNT);
len = reopcode_info[opcode].size;
assert((pos + len) <= bc_buf_len);
switch(opcode) {
case REOP_push_i32:
Expand Down
3 changes: 2 additions & 1 deletion modules/juce_core/juce_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
#endif

#if JUCE_WASM
#include <emscripten.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
Expand Down Expand Up @@ -108,7 +109,7 @@
#include <net/if.h>
#include <sys/ioctl.h>

#if ! (JUCE_ANDROID || JUCE_WASM)
#if ! (JUCE_ANDROID || JUCE_WASM || JUCE_MUSL)
#include <execinfo.h>
#endif
#endif
Expand Down
2 changes: 1 addition & 1 deletion modules/juce_core/native/juce_SharedCode_posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ inline int juce_siginterrupt ([[maybe_unused]] int sig, [[maybe_unused]] int fla
//==============================================================================
namespace
{
#if JUCE_LINUX || (JUCE_IOS && (! TARGET_OS_MACCATALYST) && (! __DARWIN_ONLY_64_BIT_INO_T)) // (this iOS stuff is to avoid a simulator bug)
#if JUCE_GLIBC || (JUCE_IOS && (! TARGET_OS_MACCATALYST) && (! __DARWIN_ONLY_64_BIT_INO_T)) // (this iOS stuff is to avoid a simulator bug)
using juce_statStruct = struct stat64;
#define JUCE_STAT stat64
#else
Expand Down
12 changes: 6 additions & 6 deletions modules/juce_core/native/juce_SystemStats_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,22 +210,22 @@ String SystemStats::getComputerName()

String SystemStats::getUserLanguage()
{
#if JUCE_BSD
#if JUCE_GLIBC
return getLocaleValue (_NL_ADDRESS_LANG_AB);
#else
if (auto langEnv = getenv ("LANG"))
return String::fromUTF8 (langEnv).upToLastOccurrenceOf (".UTF-8", false, true);

return {};
#else
return getLocaleValue (_NL_ADDRESS_LANG_AB);
#endif
}

String SystemStats::getUserRegion()
{
#if JUCE_BSD
return {};
#else
#if JUCE_GLIBC
return getLocaleValue (_NL_ADDRESS_COUNTRY_AB2);
#else
return {};
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion modules/juce_core/system/juce_SystemStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ String SystemStats::getStackBacktrace()
{
String result;

#if JUCE_ANDROID || JUCE_WASM
#if JUCE_ANDROID || JUCE_MINGW || JUCE_WASM || JUCE_MUSL
jassertfalse; // sorry, not implemented yet!

#elif JUCE_WINDOWS
Expand Down
13 changes: 11 additions & 2 deletions modules/juce_core/system/juce_TargetPlatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
- Either JUCE_LITTLE_ENDIAN or JUCE_BIG_ENDIAN.
- Either JUCE_INTEL or JUCE_ARM
- Either JUCE_GCC or JUCE_CLANG or JUCE_MSVC
- Either JUCE_GLIBC or JUCE_MUSL will be defined on Linux depending on the system's libc implementation.
*/

//==============================================================================
Expand Down Expand Up @@ -76,6 +77,8 @@
#define JUCE_ANDROID 1
#elif defined (__FreeBSD__) || defined (__OpenBSD__)
#define JUCE_BSD 1
#elif defined (__wasm__)
#define JUCE_WASM 1
#elif defined (LINUX) || defined (__linux__)
#define JUCE_LINUX 1
#elif defined (__APPLE_CPP__) || defined (__APPLE_CC__)
Expand All @@ -89,8 +92,6 @@
#else
#define JUCE_MAC 1
#endif
#elif defined (__wasm__)
#define JUCE_WASM 1
#else
#error "Unknown platform!"
#endif
Expand Down Expand Up @@ -196,6 +197,14 @@
#elif __MMX__ || __SSE__ || __amd64__
#define JUCE_INTEL 1
#endif

#if JUCE_LINUX
#ifdef __GLIBC__
#define JUCE_GLIBC 1
#else
#define JUCE_MUSL 1
#endif
#endif
#endif

//==============================================================================
Expand Down
4 changes: 3 additions & 1 deletion modules/juce_dsp/juce_dsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@
#include "widgets/juce_Chorus.cpp"

#if JUCE_USE_SIMD
#if JUCE_INTEL
#if JUCE_INTEL || defined(__riscv) || defined(__EMSCRIPTEN__)
// falkTX patch to 6.* was this so ... add those ORs above
// #if defined(__i386__) || defined(__amd64__) || defined(_M_X64) || defined(_X86_) || defined(_M_IX86) || defined(__riscv) || defined(__EMSCRIPTEN__)
#ifdef __AVX2__
#include "native/juce_SIMDNativeOps_avx.cpp"
#else
Expand Down
4 changes: 2 additions & 2 deletions modules/juce_dsp/juce_dsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
#include <juce_audio_basics/juce_audio_basics.h>
#include <juce_audio_formats/juce_audio_formats.h>

#if defined (_M_X64) || defined (__amd64__) || defined (__SSE2__) || (defined (_M_IX86_FP) && _M_IX86_FP == 2)
#if defined(_M_X64) || defined(__amd64__) || defined(__SSE2__) || (defined(_M_IX86_FP) && _M_IX86_FP == 2) || defined(__riscv) || defined(__EMSCRIPTEN__)

#if defined (_M_X64) || defined (__amd64__)
#ifndef __SSE2__
Expand Down Expand Up @@ -234,7 +234,7 @@ namespace util
#include "native/juce_SIMDNativeOps_fallback.h"

// include the correct native file for this build target CPU
#if defined (__i386__) || defined (__amd64__) || defined (_M_X64) || defined (_X86_) || defined (_M_IX86)
#if defined(__i386__) || defined(__amd64__) || defined(_M_X64) || defined(_X86_) || defined(_M_IX86) || defined(__riscv) || defined(__EMSCRIPTEN__)
#ifdef __AVX2__
#include "native/juce_SIMDNativeOps_avx.h"
#else
Expand Down
7 changes: 5 additions & 2 deletions modules/juce_graphics/fonts/harfbuzz/hb-directwrite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,11 @@ _hb_directwrite_shaper_face_data_create (hb_face_t *face)
} HB_STMT_END

data->dwrite_dll = LoadLibrary (TEXT ("DWRITE"));
if (unlikely (!data->dwrite_dll))
FAIL ("Cannot find DWrite.DLL");
if ( unlikely( !data->dwrite_dll ) )
{
delete data;
FAIL("Cannot find DWrite.DLL");
}

t_DWriteCreateFactory p_DWriteCreateFactory;

Expand Down
2 changes: 1 addition & 1 deletion modules/juce_gui_basics/components/juce_Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ bool Component::isShowing() const
return parentComponent->isShowing();

if (auto* peer = getPeer())
return peer->isShowing();
return ! peer->isMinimised();

return false;
}
Expand Down
54 changes: 50 additions & 4 deletions modules/juce_gui_basics/menus/juce_PopupMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
==============================================================================
*/

// clang-format off

namespace juce
{

Expand Down Expand Up @@ -190,7 +192,9 @@ struct ItemComponent final : public Component

static bool isAccessibilityHandlerRequired (const PopupMenu::Item& item)
{
return item.isSectionHeader || hasActiveSubMenu (item) || canBeTriggered (item);
return item.isSectionHeader || hasActiveSubMenu (item) || canBeTriggered (item) ||
// SURGE FIX : if the custom component is accessible!
(item.customComponent != nullptr && item.customComponent->isAccessible());
}

PopupMenu::Item item;
Expand All @@ -211,7 +215,13 @@ struct ItemComponent final : public Component

String getTitle() const override
{
return itemComponent.item.text;
auto res = itemComponent.item.text + (itemComponent.item.isTicked ? " (Checked)" : "");
#if JUCE_MAC
if (hasActiveSubMenu(itemComponent.item))
res += " (has SubMenu)";
#endif

return res;
}

AccessibleState getCurrentState() const override
Expand Down Expand Up @@ -645,12 +655,43 @@ struct MenuWindow final : public Component
}
else if (key.isKeyCode (KeyPress::returnKey) || key.isKeyCode (KeyPress::spaceKey))
{
triggerCurrentlyHighlightedItem();
// SURGE FIX: Use 'return key' to open submenus
if (showSubMenuFor (currentChild))
{
if (isSubMenuVisible())
activeSubMenu->selectNextItem (MenuSelectionDirection::current);
}
// END SURGE FIX:
else
{
// SURGE FIX : if I have a custom component try its keyPressed
if (currentChild && currentChild->item.customComponent != nullptr)
{
if (currentChild->item.customComponent->keyPressed(key))
{
}
else
{
triggerCurrentlyHighlightedItem();
}
}
// END SURGE FIX
else
{
triggerCurrentlyHighlightedItem();
}
}
}
else if (key.isKeyCode (KeyPress::escapeKey))
{
dismissMenu (nullptr);
}
// surge patch to work around reaper issue described in #7281
else if (key.isKeyCode(KeyPress::F10Key) && key.getModifiers().isShiftDown())
{
dismissMenu (nullptr);
}
// end surge patch
else
{
return false;
Expand Down Expand Up @@ -1258,7 +1299,12 @@ struct MenuWindow final : public Component

if (auto* mic = items.getUnchecked ((start + items.size()) % items.size()))
{
if (canBeTriggered (mic->item) || hasActiveSubMenu (mic->item))
if (canBeTriggered (mic->item) || hasActiveSubMenu (mic->item) ||
// SURGE FIX: You can select accessible menu custom components
(mic->item.customComponent != nullptr &&
mic->item.customComponent->isAccessible())
// END SURGE FIX
)
{
setCurrentlyHighlightedChild (mic);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ inline JUCE_COMRESULT addHandlersToArray (const std::vector<const AccessibilityH

*pRetVal = SafeArrayCreateVector (VT_UNKNOWN, 0, (ULONG) numHandlers);

if (pRetVal != nullptr)
if (*pRetVal != nullptr)
{
for (LONG i = 0; i < (LONG) numHandlers; ++i)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ class UIATextProvider : public UIAProviderBase,
{
return withTextInterface (pRetVal, [&] (const AccessibilityTextInterface& textInterface)
{
HRESULT hr;

*pRetVal = SafeArrayCreateVector (VT_UNKNOWN, 0, 1);

if (pRetVal != nullptr)
if (*pRetVal != nullptr)
{
auto selection = textInterface.getSelection();
auto hasSelection = ! selection.isEmpty();
Expand All @@ -95,38 +97,42 @@ class UIATextProvider : public UIAProviderBase,
hasSelection ? selection.getEnd() : cursorPos });

LONG pos = 0;
auto hr = SafeArrayPutElement (*pRetVal, &pos, static_cast<IUnknown*> (rangeProvider));

if (FAILED (hr))
return E_FAIL;
hr = SafeArrayPutElement (*pRetVal, &pos, static_cast<IUnknown*> (rangeProvider));

rangeProvider->Release();
}
else
{
hr = E_FAIL;
}

return S_OK;
return hr;
});
}

JUCE_COMRESULT GetVisibleRanges (SAFEARRAY** pRetVal) override
{
return withTextInterface (pRetVal, [&] (const AccessibilityTextInterface& textInterface)
{
*pRetVal = SafeArrayCreateVector (VT_UNKNOWN, 0, 1);
HRESULT hr;

if (pRetVal != nullptr)
*pRetVal = SafeArrayCreateVector(VT_UNKNOWN, 0, 1);

if (*pRetVal != nullptr)
{
auto* rangeProvider = new UIATextRangeProvider (*this, { 0, textInterface.getTotalNumCharacters() });

LONG pos = 0;
auto hr = SafeArrayPutElement (*pRetVal, &pos, static_cast<IUnknown*> (rangeProvider));

if (FAILED (hr))
return E_FAIL;
hr = SafeArrayPutElement (*pRetVal, &pos, static_cast<IUnknown*> (rangeProvider));

rangeProvider->Release();
}
else
{
hr = E_FAIL;
}

return S_OK;
return hr;
});
}

Expand Down
Loading