diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-03-16 22:52:09 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-03-16 22:52:09 +0400 |
commit | 9e2db2dad4ee38036a28452039656594f73b4421 (patch) | |
tree | 08c1ee02ad80ea240c8a2c6ced419babaeee2567 /source/blender | |
parent | 0fedc6e45bdcb2b159b9ab54267d70c0bb59dd72 (diff) |
revert own change: don't use memchr for strnlen, causes problems when the len is longer then the string data, instead use strnlen from freebsd.
also simplify empty string checks in logic_ops.c
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenlib/intern/string.c | 11 | ||||
-rw-r--r-- | source/blender/editors/space_logic/logic_ops.c | 23 |
2 files changed, 21 insertions, 13 deletions
diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c index 815295b8eac..906a3095f91 100644 --- a/source/blender/blenlib/intern/string.c +++ b/source/blender/blenlib/intern/string.c @@ -509,10 +509,15 @@ void BLI_timestr(double _time, char *str) } /* determine the length of a fixed-size string */ -size_t BLI_strnlen(const char *str, const size_t maxlen) +size_t BLI_strnlen(const char *s, size_t maxlen) { - const char *end = memchr(str, '\0', maxlen); - return end ? (size_t) (end - str) : maxlen; + size_t len; + + for (len = 0; len < maxlen; len++, s++) { + if (!*s) + break; + } + return len; } void BLI_ascii_strtolower(char *str, const size_t len) diff --git a/source/blender/editors/space_logic/logic_ops.c b/source/blender/editors/space_logic/logic_ops.c index 51be5262a57..5f2ecbf1b2b 100644 --- a/source/blender/editors/space_logic/logic_ops.c +++ b/source/blender/editors/space_logic/logic_ops.c @@ -122,7 +122,7 @@ static Object *edit_object_property_get(bContext *C, wmOperator *op) /* if ob_name is valid try to find the object with this name * otherwise gets the active object */ - if (BLI_strnlen(ob_name, MAX_NAME) > 0) + if (*ob_name) ob = BLI_findstring(&(CTX_data_main(C)->object), ob_name, offsetof(ID, name) + 2); else ob = ED_object_active_context(C); @@ -295,12 +295,13 @@ static int sensor_add_exec(bContext *C, wmOperator *op) prop = RNA_struct_find_property(&sens_ptr, "type"); RNA_string_get(op->ptr, "name", name); - if (BLI_strnlen(name, MAX_NAME) < 1) { + if (*name) { + BLI_strncpy(sens->name, name, sizeof(sens->name)); + } + else { RNA_property_enum_name(C, &sens_ptr, prop, RNA_property_enum_get(&sens_ptr, prop), &sens_name); BLI_strncpy(sens->name, sens_name, sizeof(sens->name)); } - else - BLI_strncpy(sens->name, name, sizeof(sens->name)); make_unique_prop_names(C, sens->name); ob->scaflag |= OB_SHOWSENS; @@ -401,12 +402,13 @@ static int controller_add_exec(bContext *C, wmOperator *op) prop = RNA_struct_find_property(&cont_ptr, "type"); RNA_string_get(op->ptr, "name", name); - if (BLI_strnlen(name, MAX_NAME) < 1) { + if (*name) { + BLI_strncpy(cont->name, name, sizeof(cont->name)); + } + else { RNA_property_enum_name(C, &cont_ptr, prop, RNA_property_enum_get(&cont_ptr, prop), &cont_name); BLI_strncpy(cont->name, cont_name, sizeof(cont->name)); } - else - BLI_strncpy(cont->name, name, sizeof(cont->name)); make_unique_prop_names(C, cont->name); /* set the controller state mask from the current object state. @@ -518,12 +520,13 @@ static int actuator_add_exec(bContext *C, wmOperator *op) prop = RNA_struct_find_property(&act_ptr, "type"); RNA_string_get(op->ptr, "name", name); - if (BLI_strnlen(name, MAX_NAME) < 1) { + if (*name) { + BLI_strncpy(act->name, name, sizeof(act->name)); + } + else { RNA_property_enum_name(C, &act_ptr, prop, RNA_property_enum_get(&act_ptr, prop), &act_name); BLI_strncpy(act->name, act_name, sizeof(act->name)); } - else - BLI_strncpy(act->name, name, sizeof(act->name)); make_unique_prop_names(C, act->name); ob->scaflag |= OB_SHOWACT; |