Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <campbell@blender.org>2022-09-10 07:09:42 +0300
committerCampbell Barton <campbell@blender.org>2022-09-10 07:13:07 +0300
commitef3c49de8186278d57d0319ab4bf4fe923b7016d (patch)
tree0ab65b060c37704e067c4a2eb7bf4489e9d8792d
parent099ae99589bf21e03bbf380613438114953dd8ea (diff)
Cleanup: early return when directories can't be found
Also reduce variable scope and assert when an invalid argument is passed to BKE_appdir_folder_id_create.
-rw-r--r--source/blender/blenkernel/intern/appdir.c1
-rw-r--r--source/blender/blenkernel/intern/studiolight.c22
-rw-r--r--source/blender/windowmanager/intern/wm_files.c16
-rw-r--r--source/blender/windowmanager/intern/wm_platform_support.c44
4 files changed, 42 insertions, 41 deletions
diff --git a/source/blender/blenkernel/intern/appdir.c b/source/blender/blenkernel/intern/appdir.c
index f4dec0aecd7..24e4305d916 100644
--- a/source/blender/blenkernel/intern/appdir.c
+++ b/source/blender/blenkernel/intern/appdir.c
@@ -734,6 +734,7 @@ const char *BKE_appdir_folder_id_create(const int folder_id, const char *subfold
BLENDER_USER_CONFIG,
BLENDER_USER_SCRIPTS,
BLENDER_USER_AUTOSAVE)) {
+ BLI_assert_unreachable();
return NULL;
}
diff --git a/source/blender/blenkernel/intern/studiolight.c b/source/blender/blenkernel/intern/studiolight.c
index f17450ac3f4..64f998ea67f 100644
--- a/source/blender/blenkernel/intern/studiolight.c
+++ b/source/blender/blenkernel/intern/studiolight.c
@@ -1166,19 +1166,21 @@ static void studiolight_add_files_from_datafolder(const int folder_id,
const char *subfolder,
int flag)
{
- struct direntry *dirs;
const char *folder = BKE_appdir_folder_id(folder_id, subfolder);
- if (folder) {
- const uint dirs_num = BLI_filelist_dir_contents(folder, &dirs);
- int i;
- for (i = 0; i < dirs_num; i++) {
- if (dirs[i].type & S_IFREG) {
- studiolight_add_file(dirs[i].path, flag);
- }
+ if (!folder) {
+ return;
+ }
+
+ struct direntry *dirs;
+ const uint dirs_num = BLI_filelist_dir_contents(folder, &dirs);
+ int i;
+ for (i = 0; i < dirs_num; i++) {
+ if (dirs[i].type & S_IFREG) {
+ studiolight_add_file(dirs[i].path, flag);
}
- BLI_filelist_free(dirs, dirs_num);
- dirs = NULL;
}
+ BLI_filelist_free(dirs, dirs_num);
+ dirs = NULL;
}
static int studiolight_flag_cmp_order(const StudioLight *sl)
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index 186edfe68d6..6d2248ba354 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -1397,29 +1397,27 @@ void wm_homefile_read_post(struct bContext *C,
void wm_history_file_read(void)
{
- char name[FILE_MAX];
- LinkNode *l, *lines;
- struct RecentFile *recent;
- const char *line;
- int num;
const char *const cfgdir = BKE_appdir_folder_id(BLENDER_USER_CONFIG, NULL);
-
if (!cfgdir) {
return;
}
+ char name[FILE_MAX];
+ LinkNode *l;
+ int num;
+
BLI_join_dirfile(name, sizeof(name), cfgdir, BLENDER_HISTORY_FILE);
- lines = BLI_file_read_as_lines(name);
+ LinkNode *lines = BLI_file_read_as_lines(name);
wm_history_files_free();
/* read list of recent opened files from recent-files.txt to memory */
for (l = lines, num = 0; l && (num < U.recent_files); l = l->next) {
- line = l->link;
+ const char *line = l->link;
/* don't check if files exist, causes slow startup for remote/external drives */
if (line[0]) {
- recent = (RecentFile *)MEM_mallocN(sizeof(RecentFile), "RecentFile");
+ struct RecentFile *recent = (RecentFile *)MEM_mallocN(sizeof(RecentFile), "RecentFile");
BLI_addtail(&(G.recent_files), recent);
recent->filepath = BLI_strdup(line);
num++;
diff --git a/source/blender/windowmanager/intern/wm_platform_support.c b/source/blender/windowmanager/intern/wm_platform_support.c
index becc2d896d0..a0519506d29 100644
--- a/source/blender/windowmanager/intern/wm_platform_support.c
+++ b/source/blender/windowmanager/intern/wm_platform_support.c
@@ -32,35 +32,35 @@
*/
static bool wm_platform_support_check_approval(const char *platform_support_key, bool update)
{
- const char *const cfgdir = BKE_appdir_folder_id(BLENDER_USER_CONFIG, NULL);
- bool result = false;
-
if (G.factory_startup) {
- return result;
+ return false;
+ }
+ const char *const cfgdir = BKE_appdir_folder_id(BLENDER_USER_CONFIG, NULL);
+ if (!cfgdir) {
+ return false;
}
- if (cfgdir) {
- char filepath[FILE_MAX];
- BLI_join_dirfile(filepath, sizeof(filepath), cfgdir, BLENDER_PLATFORM_SUPPORT_FILE);
- LinkNode *lines = BLI_file_read_as_lines(filepath);
- for (LinkNode *line_node = lines; line_node; line_node = line_node->next) {
- char *line = line_node->link;
- if (STREQ(line, platform_support_key)) {
- result = true;
- break;
- }
+ bool result = false;
+ char filepath[FILE_MAX];
+ BLI_join_dirfile(filepath, sizeof(filepath), cfgdir, BLENDER_PLATFORM_SUPPORT_FILE);
+ LinkNode *lines = BLI_file_read_as_lines(filepath);
+ for (LinkNode *line_node = lines; line_node; line_node = line_node->next) {
+ char *line = line_node->link;
+ if (STREQ(line, platform_support_key)) {
+ result = true;
+ break;
}
+ }
- if (!result && update) {
- FILE *fp = BLI_fopen(filepath, "a");
- if (fp) {
- fprintf(fp, "%s\n", platform_support_key);
- fclose(fp);
- }
+ if (!result && update) {
+ FILE *fp = BLI_fopen(filepath, "a");
+ if (fp) {
+ fprintf(fp, "%s\n", platform_support_key);
+ fclose(fp);
}
-
- BLI_file_free_lines(lines);
}
+
+ BLI_file_free_lines(lines);
return result;
}