[Bf-blender-cvs] [70f2389] master: Code cleanup: be less vague checking invalid index values

Campbell Barton noreply at git.blender.org
Fri Jan 31 16:04:03 CET 2014


Commit: 70f2389f5a9052efab319d0b21999db7bcfc73b0
Author: Campbell Barton
Date:   Sat Feb 1 01:45:09 2014 +1100
https://developer.blender.org/rB70f2389f5a9052efab319d0b21999db7bcfc73b0

Code cleanup: be less vague checking invalid index values

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

M	source/blender/blenkernel/BKE_fcurve.h
M	source/blender/blenkernel/intern/customdata.c
M	source/blender/blenkernel/intern/fmodifier.c
M	source/blender/blenkernel/intern/tracking.c
M	source/blender/editors/include/ED_object.h
M	source/blender/editors/object/object_modifier.c
M	source/blender/editors/object/object_vgroup.c
M	source/blender/editors/screen/area.c
M	source/blender/editors/transform/transform_conversions.c
M	source/blender/makesrna/intern/rna_color.c
M	source/blender/makesrna/intern/rna_key.c
M	source/blender/makesrna/intern/rna_mask.c
M	source/blender/makesrna/intern/rna_texture.c
M	source/blender/makesrna/intern/rna_tracking.c

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

diff --git a/source/blender/blenkernel/BKE_fcurve.h b/source/blender/blenkernel/BKE_fcurve.h
index 5ad378b..06598a2 100644
--- a/source/blender/blenkernel/BKE_fcurve.h
+++ b/source/blender/blenkernel/BKE_fcurve.h
@@ -178,13 +178,13 @@ FModifierTypeInfo *get_fmodifier_typeinfo(int type);
 struct FModifier *add_fmodifier(ListBase *modifiers, int type);
 struct FModifier *copy_fmodifier(struct FModifier *src);
 void copy_fmodifiers(ListBase *dst, ListBase *src);
-int remove_fmodifier(ListBase *modifiers, struct FModifier *fcm);
+bool remove_fmodifier(ListBase *modifiers, struct FModifier *fcm);
 void free_fmodifiers(ListBase *modifiers);
 
 struct FModifier *find_active_fmodifier(ListBase *modifiers);
 void set_active_fmodifier(ListBase *modifiers, struct FModifier *fcm);
 
-short list_has_suitable_fmodifier(ListBase *modifiers, int mtype, short acttype);
+bool list_has_suitable_fmodifier(ListBase *modifiers, int mtype, short acttype);
 
 FModifierStackStorage *evaluate_fmodifiers_storage_new(ListBase *modifiers);
 void evaluate_fmodifiers_storage_free(FModifierStackStorage *storage);
diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index fc123d3..5a5b9f1 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -1793,7 +1793,7 @@ bool CustomData_free_layer_active(CustomData *data, int type, int totelem)
 {
 	int index = 0;
 	index = CustomData_get_active_layer_index(data, type);
-	if (index < 0) return 0;
+	if (index == -1) return 0;
 	return CustomData_free_layer(data, type, totelem, index);
 }
 
@@ -1838,7 +1838,7 @@ void *CustomData_duplicate_referenced_layer(struct CustomData *data, const int t
 
 	/* get the layer index of the first layer of type */
 	layer_index = CustomData_get_active_layer_index(data, type);
-	if (layer_index < 0) return NULL;
+	if (layer_index == -1) return NULL;
 
 	layer = &data->layers[layer_index];
 
@@ -1871,7 +1871,7 @@ void *CustomData_duplicate_referenced_layer_named(struct CustomData *data,
 
 	/* get the layer index of the desired layer */
 	layer_index = CustomData_get_named_layer_index(data, type, name);
-	if (layer_index < 0) return NULL;
+	if (layer_index == -1) return NULL;
 
 	layer = &data->layers[layer_index];
 
@@ -1903,7 +1903,7 @@ bool CustomData_is_referenced_layer(struct CustomData *data, int type)
 
 	/* get the layer index of the first layer of type */
 	layer_index = CustomData_get_active_layer_index(data, type);
-	if (layer_index < 0) return 0;
+	if (layer_index == -1) return 0;
 
 	layer = &data->layers[layer_index];
 
@@ -2007,7 +2007,7 @@ void CustomData_copy_data_named(const CustomData *source, CustomData *dest,
 		dest_i = CustomData_get_named_layer_index(dest, source->layers[src_i].type, source->layers[src_i].name);
 
 		/* if we found a matching layer, copy the data */
-		if (dest_i > -1) {
+		if (dest_i != -1) {
 			CustomData_copy_data_layer(source, dest, src_i, dest_i, source_index, dest_index, count);
 		}
 	}
@@ -2148,7 +2148,7 @@ void *CustomData_get(const CustomData *data, int index, int type)
 
 	/* get the layer index of the active layer of type */
 	layer_index = CustomData_get_active_layer_index(data, type);
-	if (layer_index < 0) return NULL;
+	if (layer_index == -1) return NULL;
 
 	/* get the offset of the desired element */
 	offset = layerType_getInfo(type)->size * index;
@@ -2165,7 +2165,7 @@ void *CustomData_get_n(const CustomData *data, int type, int index, int n)
 
 	/* get the layer index of the first layer of type */
 	layer_index = data->typemap[type];
-	if (layer_index < 0) return NULL;
+	if (layer_index == -1) return NULL;
 
 	offset = layerType_getInfo(type)->size * index;
 	return (char *)data->layers[layer_index + n].data + offset;
@@ -2175,7 +2175,7 @@ void *CustomData_get_layer(const CustomData *data, int type)
 {
 	/* get the layer index of the active layer of type */
 	int layer_index = CustomData_get_active_layer_index(data, type);
-	if (layer_index < 0) return NULL;
+	if (layer_index == -1) return NULL;
 
 	return data->layers[layer_index].data;
 }
@@ -2184,7 +2184,7 @@ void *CustomData_get_layer_n(const CustomData *data, int type, int n)
 {
 	/* get the layer index of the active layer of type */
 	int layer_index = CustomData_get_layer_index_n(data, type, n);
-	if (layer_index < 0) return NULL;
+	if (layer_index == -1) return NULL;
 
 	return data->layers[layer_index].data;
 }
@@ -2193,7 +2193,7 @@ void *CustomData_get_layer_named(const struct CustomData *data, int type,
                                  const char *name)
 {
 	int layer_index = CustomData_get_named_layer_index(data, type, name);
-	if (layer_index < 0) return NULL;
+	if (layer_index == -1) return NULL;
 
 	return data->layers[layer_index].data;
 }
@@ -2202,7 +2202,7 @@ int CustomData_get_offset(const CustomData *data, int type)
 {
 	/* get the layer index of the active layer of type */
 	int layer_index = CustomData_get_active_layer_index(data, type);
-	if (layer_index < 0) return -1;
+	if (layer_index == -1) return -1;
 
 	return data->layers[layer_index].offset;
 }
@@ -2211,7 +2211,7 @@ int CustomData_get_n_offset(const CustomData *data, int type, int n)
 {
 	/* get the layer index of the active layer of type */
 	int layer_index = CustomData_get_layer_index_n(data, type, n);
-	if (layer_index < 0) return -1;
+	if (layer_index == -1) return -1;
 
 	return data->layers[layer_index].offset;
 }
@@ -2221,7 +2221,7 @@ bool CustomData_set_layer_name(const CustomData *data, int type, int n, const ch
 	/* get the layer index of the first layer of type */
 	int layer_index = CustomData_get_layer_index_n(data, type, n);
 
-	if (layer_index < 0) return false;
+	if (layer_index == -1) return false;
 	if (!name) return false;
 	
 	BLI_strncpy(data->layers[layer_index].name, name, sizeof(data->layers[layer_index].name));
@@ -2234,7 +2234,7 @@ void *CustomData_set_layer(const CustomData *data, int type, void *ptr)
 	/* get the layer index of the first layer of type */
 	int layer_index = CustomData_get_active_layer_index(data, type);
 
-	if (layer_index < 0) return NULL;
+	if (layer_index == -1) return NULL;
 
 	data->layers[layer_index].data = ptr;
 
@@ -2245,7 +2245,7 @@ void *CustomData_set_layer_n(const struct CustomData *data, int type, int n, voi
 {
 	/* get the layer index of the first layer of type */
 	int layer_index = CustomData_get_layer_index_n(data, type, n);
-	if (layer_index < 0) return NULL;
+	if (layer_index == -1) return NULL;
 
 	data->layers[layer_index].data = ptr;
 
@@ -2614,7 +2614,7 @@ void *CustomData_bmesh_get(const CustomData *data, void *block, int type)
 	
 	/* get the layer index of the first layer of type */
 	layer_index = CustomData_get_active_layer_index(data, type);
-	if (layer_index < 0) return NULL;
+	if (layer_index == -1) return NULL;
 
 	return (char *)block + data->layers[layer_index].offset;
 }
@@ -2625,7 +2625,7 @@ void *CustomData_bmesh_get_n(const CustomData *data, void *block, int type, int
 	
 	/* get the layer index of the first layer of type */
 	layer_index = CustomData_get_layer_index(data, type);
-	if (layer_index < 0) return NULL;
+	if (layer_index == -1) return NULL;
 
 	return (char *)block + data->layers[layer_index + n].offset;
 }
@@ -3070,7 +3070,7 @@ void CustomData_validate_layer_name(const CustomData *data, int type, const char
 	if (name[0])
 		index = CustomData_get_named_layer_index(data, type, name);
 
-	if (index < 0) {
+	if (index == -1) {
 		/* either no layer was specified, or the layer we want has been
 		 * deleted, so assign the active layer to name
 		 */
@@ -3319,7 +3319,7 @@ void CustomData_external_add(CustomData *data, ID *UNUSED(id), int type, int UNU
 	int layer_index;
 
 	layer_index = CustomData_get_active_layer_index(data, type);
-	if (layer_index < 0) return;
+	if (layer_index == -1) return;
 
 	layer = &data->layers[layer_index];
 
@@ -3343,7 +3343,7 @@ void CustomData_external_remove(CustomData *data, ID *id, int type, int totelem)
 	int layer_index; // i, remove_file;
 
 	layer_index = CustomData_get_active_layer_index(data, type);
-	if (layer_index < 0) return;
+	if (layer_index == -1) return;
 
 	layer = &data->layers[layer_index];
 
@@ -3377,7 +3377,7 @@ bool CustomData_external_test(CustomData *data, int type)
 	int layer_index;
 
 	layer_index = CustomData_get_active_layer_index(data, type);
-	if (layer_index < 0) return false;
+	if (layer_index == -1) return false;
 
 	layer = &data->layers[layer_index];
 	return (layer->flag & CD_FLAG_EXTERNAL) != 0;
diff --git a/source/blender/blenkernel/intern/fmodifier.c b/source/blender/blenkernel/intern/fmodifier.c
index 3436728..325a26d 100644
--- a/source/blender/blenkernel/intern/fmodifier.c
+++ b/source/blender/blenkernel/intern/fmodifier.c
@@ -1165,7 +1165,7 @@ void copy_fmodifiers(ListBase *dst, ListBase *src)
 }
 
 /* Remove and free the given F-Modifier from the given stack  */
-int remove_fmodifier(ListBase *modifiers, FModifier *fcm)
+bool remove_fmodifier(ListBase *modifiers, FModifier *fcm)
 {
 	FModifierTypeInfo *fmi = fmodifier_get_typeinfo(fcm);
 	
@@ -1252,7 +1252,7 @@ void set_active_fmodifier(ListBase *modifiers, FModifier *fcm)
  *	- mtype - type of modifier (if 0, doesn't matter)
  *	- acttype - type of action to perform (if -1, doesn't matter)
  */
-short list_has_suitable_fmodifier(ListBase *modifiers, int mtype, short acttype)
+bool list_has_suitable_fmodifier(ListBase *modifiers, int mtype, short acttype)
 {
 	FModifier *fcm;
 	
diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c
index ab314d8..fbca675 100644
--- a/source/blender/blenkernel/intern/tracking.c
+++ b/source/blender/blenkernel/intern/tracking.c
@@ -769,7 +769,7 @@ MovieTrackingTrack *BKE_tracking_track_get_active(MovieTracking *tracking)
 	tracksbase = BKE_tracking_get_active_tracks(tracking);
 
 	/* check that active track is in current tracks list */
-	if (BLI_findindex(tracksbase, tracking->act_track) >= 0)
+	if (BLI_findindex(tracksbase, tracking->act_track) != -1)
 		return tracking->act_track;
 
 	return NULL;
@@ -1284,7 +1284,7 @@ MovieTrackingPlaneTrack *BKE_tracking_plane_track_get_active(struct MovieTrackin
 	pl

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list