From 3005614c8ddcd116f0505c104d07be83f1bf2246 Mon Sep 17 00:00:00 2001
From: Harley Acheson <harley.acheson@gmail.com>
Date: Tue, 14 Nov 2023 21:16:22 +0100
Subject: [PATCH] Fix #114855: Crash Loading Win32 Quick Access

Replace use of macro FAILED with explicit checks for S_OK returns. Some
of these functions can return S_FALSE, which indicates a negative
condition that is not failure. It is not caught by the FAILED macro.
Therefore this function will fail in circumstances where the quick
access folder is not found or perhaps empty.

Pull Request: https://projects.blender.org/blender/blender/pulls/114866
---
 .../editors/space_file/fsmenu_system.cc       | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/source/blender/editors/space_file/fsmenu_system.cc b/source/blender/editors/space_file/fsmenu_system.cc
index d7f7dc6ae52..0706aaaf5b8 100644
--- a/source/blender/editors/space_file/fsmenu_system.cc
+++ b/source/blender/editors/space_file/fsmenu_system.cc
@@ -167,28 +167,27 @@ static void fsmenu_add_windows_quick_access(FSMenu *fsmenu,
                                             FSMenuInsert flag)
 {
   Microsoft::WRL::ComPtr<IShellDispatch> shell;
-  if (FAILED(
-          CoCreateInstance(CLSID_Shell, nullptr, CLSCTX_ALL, IID_PPV_ARGS(shell.GetAddressOf()))))
-  {
+  if (CoCreateInstance(CLSID_Shell, nullptr, CLSCTX_ALL, IID_PPV_ARGS(shell.GetAddressOf())) !=
+      S_OK) {
     return;
   }
 
   /* Open Quick Access folder. */
   Microsoft::WRL::ComPtr<Folder> dir;
-  if (FAILED(shell->NameSpace(_variant_t(L"shell:::{679f85cb-0220-4080-b29b-5540cc05aab6}"),
-                              dir.GetAddressOf())))
+  if (shell->NameSpace(_variant_t(L"shell:::{679f85cb-0220-4080-b29b-5540cc05aab6}"),
+                       dir.GetAddressOf()) != S_OK)
   {
     return;
   }
 
   /* Get FolderItems. */
   Microsoft::WRL::ComPtr<FolderItems> items;
-  if (FAILED(dir->Items(items.GetAddressOf()))) {
+  if (dir->Items(items.GetAddressOf()) != S_OK) {
     return;
   }
 
   long count = 0;
-  if (FAILED(items->get_Count(&count))) {
+  if (items->get_Count(&count) != S_OK) {
     return;
   }
 
@@ -196,18 +195,18 @@ static void fsmenu_add_windows_quick_access(FSMenu *fsmenu,
   for (long i = 0; i < count; i++) {
     Microsoft::WRL::ComPtr<FolderItem> item;
 
-    if (FAILED(items->Item(_variant_t(i), item.GetAddressOf()))) {
+    if (items->Item(_variant_t(i), item.GetAddressOf()) != S_OK) {
       continue;
     }
 
     VARIANT_BOOL isFolder;
     /* Skip if it's not a folder. */
-    if (FAILED(item->get_IsFolder(&isFolder)) || isFolder == VARIANT_FALSE) {
+    if (item->get_IsFolder(&isFolder) != S_OK || isFolder == VARIANT_FALSE) {
       continue;
     }
 
     _bstr_t path;
-    if (FAILED(item->get_Path(path.GetAddress()))) {
+    if (item->get_Path(path.GetAddress()) != S_OK) {
       continue;
     }
 
-- 
GitLab