revert own change: don't use memchr for strnlen, causes problems when the len is...
authorCampbell Barton <ideasman42@gmail.com>
Sat, 16 Mar 2013 18:52:09 +0000 (18:52 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 16 Mar 2013 18:52:09 +0000 (18:52 +0000)
also simplify empty string checks in logic_ops.c

source/blender/blenlib/intern/string.c
source/blender/editors/space_logic/logic_ops.c

index 815295b8eace38ab1c91f07aac4b4cd70992e335..906a3095f91c610135968d62c91b80ad6dbbcf62 100644 (file)
@@ -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)
index 51be5262a5747c07cea9e733ea7da971067732f5..5f2ecbf1b2bf4cb857ac8bb1bb09036811dcc96e 100644 (file)
@@ -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;