Skip to content

Commit

Permalink
Use reference to prevent unnecessary copy.
Browse files Browse the repository at this point in the history
assert opcode before it's used.
Don't fail to delete memory even though it's unlikely to occur.
Handle situation when SHBrowseForFolder is cancelled (returns null).
Several places appear to be checking the wrong thing after calling SafeArrayCreateVector.
  • Loading branch information
David Lowndes authored and David Lowndes committed Nov 18, 2024
1 parent d418c96 commit 341fe4a
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 31 deletions.
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
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
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
29 changes: 16 additions & 13 deletions modules/juce_gui_basics/native/juce_FileChooser_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,25 +451,28 @@ class Win32NativeFileChooser final : private Thread

LPITEMIDLIST list = SHBrowseForFolder (&bi);

if (! SHGetPathFromIDListW (list, files))
if ( list != nullptr )
{
files[0] = 0;
returnedString.clear();
}
if (!SHGetPathFromIDListW(list, files))
{
files[0] = 0;
returnedString.clear();
}

LPMALLOC al;
LPMALLOC al;

if (list != nullptr && SUCCEEDED (SHGetMalloc (&al)))
al->Free (list);
if (SUCCEEDED(SHGetMalloc(&al)))
al->Free(list);

if (files[0] != 0)
{
File result (String (files.get()));
if (files[0] != 0)
{
File result(String(files.get()));

if (returnedString.isNotEmpty())
result = result.getSiblingFile (returnedString);
if (returnedString.isNotEmpty())
result = result.getSiblingFile(returnedString);

selections.add (URL (result));
selections.add(URL(result));
}
}
}
else
Expand Down

0 comments on commit 341fe4a

Please sign in to comment.