[Bf-blender-cvs] [bfb6155] asset-experiments: Fix some fileops operators that could try to get out-of-bound indices.

Bastien Montagne noreply at git.blender.org
Tue Jun 16 17:33:27 CEST 2015


Commit: bfb615546682103f09f3f23ead5e0083cf204889
Author: Bastien Montagne
Date:   Tue Jun 16 15:40:58 2015 +0200
Branches: asset-experiments
https://developer.blender.org/rBbfb615546682103f09f3f23ead5e0083cf204889

Fix some fileops operators that could try to get out-of-bound indices.

Also, some minor reordering in full-block-recaching, currently could not create
issues but better be safe & logic here.

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

M	source/blender/editors/space_file/file_ops.c
M	source/blender/editors/space_file/filelist.c

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

diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index b9de2e0..674446d 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -314,13 +314,12 @@ static int file_border_select_modal(bContext *C, wmOperator *op, const wmEvent *
 	result = WM_border_select_modal(C, op, event);
 
 	if (result == OPERATOR_RUNNING_MODAL) {
-
 		WM_operator_properties_border_to_rcti(op, &rect);
 
 		BLI_rcti_isect(&(ar->v2d.mask), &rect, &rect);
 
 		sel = file_selection_get(C, &rect, 0);
-		if ( (sel.first != params->sel_first) || (sel.last != params->sel_last) ) {
+		if ((sel.first != params->sel_first) || (sel.last != params->sel_last)) {
 			int idx;
 
 			file_deselect_all(sfile, FILE_SEL_HIGHLIGHTED);
@@ -421,8 +420,9 @@ static int file_select_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 
 	if (sfile && sfile->params) {
 		int idx = sfile->params->highlight_file;
+		int numfiles = filelist_numfiles(sfile->files);
 
-		if (idx >= 0) {
+		if ((idx >= 0) && (idx < numfiles)) {
 			struct FileDirEntry *file = filelist_file(sfile->files, idx);
 			if (FILENAME_IS_CURRPAR(file->relpath)) {
 				/* skip - If a readonly file (".." or ".") is selected, skip deselect all! */
@@ -1971,29 +1971,34 @@ static int file_rename_exec(bContext *C, wmOperator *UNUSED(op))
 
 static int file_rename_poll(bContext *C)
 {
-	int poll = ED_operator_file_active(C);
+	bool poll = ED_operator_file_active(C);
 	SpaceFile *sfile = CTX_wm_space_file(C);
 
 	if (sfile && sfile->params) {
 		int idx = sfile->params->highlight_file;
+		int numfiles = filelist_numfiles(sfile->files);
 
-		if (idx >= 0) {
+		if ((0 <= idx) && (idx < numfiles)) {
 			FileDirEntry *file = filelist_file(sfile->files, idx);
 			if (FILENAME_IS_CURRPAR(file->relpath)) {
-				poll = 0;
+				poll = false;
 			}
 		}
 
 		if (sfile->params->highlight_file < 0) {
-			poll = 0;
+			poll = false;
 		}
 		else {
 			char dir[FILE_MAX];
-			if (filelist_islibrary(sfile->files, dir, NULL)) poll = 0;
+			if (filelist_islibrary(sfile->files, dir, NULL)) {
+				poll = false;
+			}
 		}
 	}
-	else
-		poll = 0;
+	else {
+		poll = false;
+	}
+
 	return poll;
 }
 
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index d95f128..24406aa 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -1407,7 +1407,7 @@ static FileDirEntry *filelist_file_ex(struct FileList *filelist, const int index
 		return NULL;
 	}
 
-	printf("requesting file %d (not yet cached)\n", index);
+//	printf("requesting file %d (not yet cached)\n", index);
 
 	/* Else, we have to add new entry to 'misc' cache - and possibly make room for it first! */
 	ret = filelist_file_create_entry(filelist, index);
@@ -1549,7 +1549,7 @@ bool filelist_file_cache_block(struct FileList *filelist, const int index)
 	int i;
 
 	if ((index < 0) || (index >= nbr_entries)) {
-		printf("Wrong index %d ([%d:%d])", index, 0, nbr_entries);
+//		printf("Wrong index %d ([%d:%d])", index, 0, nbr_entries);
 		return false;
 	}
 
@@ -1577,6 +1577,10 @@ bool filelist_file_cache_block(struct FileList *filelist, const int index)
 
 //			printf("Full Recaching!\n");
 
+			if (cache->previews_pool) {
+				filelist_cache_previews_clear(cache);
+			}
+
 			if (idx1 + size1 > cache_size) {
 				size2 = idx1 + size1 - cache_size;
 				size1 -= size2;
@@ -1584,18 +1588,15 @@ bool filelist_file_cache_block(struct FileList *filelist, const int index)
 			}
 			filelist_file_cache_block_release(filelist, size1, idx1);
 
+			cache->block_start_index = cache->block_end_index = cache->block_cursor = 0;
+
 			/* New cached block does not overlap existing one, simple. */
 			if (!filelist_file_cache_block_create(filelist, start_index, end_index - start_index, 0)) {
 				return false;
 			}
 
-			if (cache->previews_pool) {
-				filelist_cache_previews_clear(cache);
-			}
-
 			cache->block_start_index = start_index;
 			cache->block_end_index = end_index;
-			cache->block_cursor = 0;
 		}
 		else {
 //			printf("Partial Recaching!\n");




More information about the Bf-blender-cvs mailing list