Commit: fc2a64e21a1f7253f2f523c93fc0ec62f639db95
Author: Harley Acheson
Date:   Thu Feb 2 08:01:43 2023 -0800
Branches: master
https://developer.blender.org/rBfc2a64e21a1f7253f2f523c93fc0ec62f639db95

Win32: Better Error Handling in BLI_file_attributes

After Win32 API call GetFileAttributesW, check for
INVALID_FILE_ATTRIBUTES, which is returned on error,
usually if file not found.

See D17176 for more details.

Differential Revision: https://developer.blender.org/D17176

Reviewed by Ray Molenkamp

===================================================================

M       source/blender/blenlib/intern/storage.c

===================================================================

diff --git a/source/blender/blenlib/intern/storage.c 
b/source/blender/blenlib/intern/storage.c
index c04fc41ab4d..8c212bf1758 100644
--- a/source/blender/blenlib/intern/storage.c
+++ b/source/blender/blenlib/intern/storage.c
@@ -209,7 +209,14 @@ eFileAttributes BLI_file_attributes(const char *path)
   if (conv_utf_8_to_16(path, wline, ARRAY_SIZE(wline)) != 0) {
     return ret;
   }
+
   DWORD attr = GetFileAttributesW(wline);
+  BLI_assert_msg(attr != INVALID_FILE_ATTRIBUTES,
+                 "BLI_file_attributes should only be called on existing 
files.");
+  if (attr == INVALID_FILE_ATTRIBUTES) {
+    return ret;
+  }
+
   if (attr & FILE_ATTRIBUTE_READONLY) {
     ret |= FILE_ATTR_READONLY;
   }

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to