Fix #20245: datablock names allowed entering 22 characters but can
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 9 Dec 2009 18:03:44 +0000 (18:03 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 9 Dec 2009 18:03:44 +0000 (18:03 +0000)
only accept 21.

source/blender/editors/interface/interface_handlers.c
source/blender/makesrna/intern/rna_access.c

index c7c0849927ce0f93c10dd705882e6326025859e8..fe6635d60ab8d324cf0ff657c5b863f3a5e37039 100644 (file)
@@ -1079,9 +1079,9 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, sho
 
        uiStyleFontSet(&style->widget);
 
-       origstr= MEM_callocN(sizeof(char)*(data->maxlen+1), "ui_textedit origstr");
+       origstr= MEM_callocN(sizeof(char)*data->maxlen, "ui_textedit origstr");
        
-       BLI_strncpy(origstr, but->drawstr, data->maxlen+1);
+       BLI_strncpy(origstr, but->drawstr, data->maxlen);
        but->pos= strlen(origstr)-but->ofs;
        
        /* XXX solve generic */
@@ -1130,7 +1130,7 @@ static int ui_textedit_type_ascii(uiBut *but, uiHandleButtonData *data, char asc
                        changed= ui_textedit_delete_selection(but, data);
 
                len= strlen(str);
-               if(len < data->maxlen) {
+               if(len+1 < data->maxlen) {
                        for(x= data->maxlen; x>but->pos; x--)
                                str[x]= str[x-1];
                        str[but->pos]= ascii;
@@ -1365,7 +1365,7 @@ static int ui_textedit_copypaste(uiBut *but, uiHandleButtonData *data, int paste
                        for (y=0; y<strlen(buf); y++)
                        {
                                /* add contents of buffer */
-                               if(len < data->maxlen) {
+                               if(len+1 < data->maxlen) {
                                        for(x= data->maxlen; x>but->pos; x--)
                                                str[x]= str[x-1];
                                        str[but->pos]= buf[y];
@@ -1411,8 +1411,8 @@ static void ui_textedit_begin(bContext *C, uiBut *but, uiHandleButtonData *data)
 
        /* retrieve string */
        data->maxlen= ui_get_but_string_max_length(but);
-       data->str= MEM_callocN(sizeof(char)*(data->maxlen+1), "textedit str");
-       ui_get_but_string(but, data->str, data->maxlen+1);
+       data->str= MEM_callocN(sizeof(char)*data->maxlen, "textedit str");
+       ui_get_but_string(but, data->str, data->maxlen);
 
        data->origstr= BLI_strdup(data->str);
        data->selextend= 0;
index 174cb13b0cd6d1c4b1ce8baa59abb9572ec2a6c1..7bfb6d7249f0a37ad11ea19fe19ae08a798e2624 100644 (file)
@@ -885,6 +885,7 @@ void RNA_property_float_ui_range(PointerRNA *ptr, PropertyRNA *prop, float *soft
        *precision= (float)fprop->precision;
 }
 
+/* this is the max length including \0 terminator */
 int RNA_property_string_maxlength(PropertyRNA *prop)
 {
        StringPropertyRNA *sprop= (StringPropertyRNA*)rna_ensure_property(prop);
@@ -1588,6 +1589,7 @@ char *RNA_property_string_get_alloc(PointerRNA *ptr, PropertyRNA *prop, char *fi
        return buf;
 }
 
+/* this is the length without \0 terminator */
 int RNA_property_string_length(PointerRNA *ptr, PropertyRNA *prop)
 {
        StringPropertyRNA *sprop= (StringPropertyRNA*)prop;