use BLI_strncpy and BLI_snprintf when the size of the string is known.
[blender.git] / source / blender / blenkernel / intern / ipo.c
index 71ca79706db58f4f6482623b75a17f05b0c2fb59..40fe36268488a772fadde42751a17086f1190b61 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
@@ -43,7 +43,8 @@
 #include <string.h>
 #include <stddef.h>
 
 #include <string.h>
 #include <stddef.h>
 
-#include "MEM_guardedalloc.h"
+/* since we have versioning code here */
+#define DNA_DEPRECATED_ALLOW
 
 #include "DNA_anim_types.h"
 #include "DNA_constraint_types.h"
 
 #include "DNA_anim_types.h"
 #include "DNA_constraint_types.h"
@@ -73,6 +74,7 @@
 #include "BKE_nla.h"
 #include "BKE_sequencer.h"
 
 #include "BKE_nla.h"
 #include "BKE_sequencer.h"
 
+#include "MEM_guardedalloc.h"
 
 /* *************************************************** */
 /* Old-Data Freeing Tools */
 
 /* *************************************************** */
 /* Old-Data Freeing Tools */
@@ -326,9 +328,9 @@ static char *shapekey_adrcodes_to_paths (int adrcode, int *UNUSED(array_index))
        /* block will be attached to ID_KE block, and setting that we alter is the 'value' (which sets keyblock.curval) */
        // XXX adrcode 0 was dummy 'speed' curve 
        if (adrcode == 0) 
        /* block will be attached to ID_KE block, and setting that we alter is the 'value' (which sets keyblock.curval) */
        // XXX adrcode 0 was dummy 'speed' curve 
        if (adrcode == 0) 
-               sprintf(buf, "speed");
+               strcpy(buf, "speed");
        else
        else
-               sprintf(buf, "key_blocks[%d].value", adrcode);
+               BLI_snprintf(buf, sizeof(buf), "key_blocks[%d].value", adrcode);
        return buf;
 }
 
        return buf;
 }
 
@@ -703,14 +705,7 @@ static const char *world_adrcodes_to_paths (int adrcode, int *array_index)
                        return "mist.start";
                case WO_MISTHI:
                        return "mist.height";
                        return "mist.start";
                case WO_MISTHI:
                        return "mist.height";
-               
-       /*      Star Color is unused -- recommend removal */
-       /*      case WO_STAR_R:
-                       *array_index= 0; return "stars.color";
-               case WO_STAR_G:
-                       *array_index= 1; return "stars.color";
-               case WO_STAR_B:
-                       *array_index= 2; return "stars.color"; */
+
                case WO_STAR_R:
                case WO_STAR_G:
                case WO_STAR_B:
                case WO_STAR_R:
                case WO_STAR_G:
                case WO_STAR_B:
@@ -914,15 +909,18 @@ static char *get_rna_access (int blocktype, int adrcode, char actname[], char co
                if (array_index)
                        *array_index= dummy_index;
        }
                if (array_index)
                        *array_index= dummy_index;
        }
-       
+
+       /* 'buf' _must_ be initialized in this block */
        /* append preceding bits to path */
        /* append preceding bits to path */
+       /* note, strings are not escapted and they should be! */
        if ((actname && actname[0]) && (constname && constname[0])) {
                /* Constraint in Pose-Channel */
        if ((actname && actname[0]) && (constname && constname[0])) {
                /* Constraint in Pose-Channel */
-               sprintf(buf, "pose.bones[\"%s\"].constraints[\"%s\"]", actname, constname);
+               BLI_snprintf(buf, sizeof(buf), "pose.bones[\"%s\"].constraints[\"%s\"]", actname, constname);
        }
        else if (actname && actname[0]) {
                if ((blocktype == ID_OB) && strcmp(actname, "Object")==0) {
                        /* Actionified "Object" IPO's... no extra path stuff needed */
        }
        else if (actname && actname[0]) {
                if ((blocktype == ID_OB) && strcmp(actname, "Object")==0) {
                        /* Actionified "Object" IPO's... no extra path stuff needed */
+                       buf[0]= '\0'; /* empty string */
                }
                else if ((blocktype == ID_KE) && strcmp(actname, "Shape")==0) {
                        /* Actionified "Shape" IPO's - these are forced onto object level via the action container there... */
                }
                else if ((blocktype == ID_KE) && strcmp(actname, "Shape")==0) {
                        /* Actionified "Shape" IPO's - these are forced onto object level via the action container there... */
@@ -930,19 +928,21 @@ static char *get_rna_access (int blocktype, int adrcode, char actname[], char co
                }
                else {
                        /* Pose-Channel */
                }
                else {
                        /* Pose-Channel */
-                       sprintf(buf, "pose.bones[\"%s\"]", actname);
+                       BLI_snprintf(buf, sizeof(buf), "pose.bones[\"%s\"]", actname);
                }
        }
        else if (constname && constname[0]) {
                /* Constraint in Object */
                }
        }
        else if (constname && constname[0]) {
                /* Constraint in Object */
-               sprintf(buf, "constraints[\"%s\"]", constname);
+               BLI_snprintf(buf, sizeof(buf), "constraints[\"%s\"]", constname);
        }
        else if (seq) {
                /* Sequence names in Scene */
        }
        else if (seq) {
                /* Sequence names in Scene */
-               sprintf(buf, "sequence_editor.sequences_all[\"%s\"]", seq->name+2);
+               BLI_snprintf(buf, sizeof(buf), "sequence_editor.sequences_all[\"%s\"]", seq->name+2);
        }
        }
-       else
+       else {
                buf[0]= '\0'; /* empty string */
                buf[0]= '\0'; /* empty string */
+       }
+
        BLI_dynstr_append(path, buf);
        
        /* need to add dot before property if there was anything precceding this */
        BLI_dynstr_append(path, buf);
        
        /* need to add dot before property if there was anything precceding this */
@@ -954,7 +954,7 @@ static char *get_rna_access (int blocktype, int adrcode, char actname[], char co
        
        /* if there was no array index pointer provided, add it to the path */
        if (array_index == NULL) {
        
        /* if there was no array index pointer provided, add it to the path */
        if (array_index == NULL) {
-               sprintf(buf, "[\"%d\"]", dummy_index);
+               BLI_snprintf(buf, sizeof(buf), "[\"%d\"]", dummy_index);
                BLI_dynstr_append(path, buf);
        }
        
                BLI_dynstr_append(path, buf);
        }
        
@@ -1032,12 +1032,14 @@ static ChannelDriver *idriver_to_cdriver (IpoDriver *idriver)
                                        /* first bone target */
                                dtar= &dvar->targets[0];
                                dtar->id= (ID *)idriver->ob;
                                        /* first bone target */
                                dtar= &dvar->targets[0];
                                dtar->id= (ID *)idriver->ob;
+                               dtar->idtype= ID_OB;
                                if (idriver->name[0])
                                        BLI_strncpy(dtar->pchan_name, idriver->name, sizeof(dtar->pchan_name));
                                
                                        /* second bone target (name was stored in same var as the first one) */
                                dtar= &dvar->targets[1];
                                dtar->id= (ID *)idriver->ob;
                                if (idriver->name[0])
                                        BLI_strncpy(dtar->pchan_name, idriver->name, sizeof(dtar->pchan_name));
                                
                                        /* second bone target (name was stored in same var as the first one) */
                                dtar= &dvar->targets[1];
                                dtar->id= (ID *)idriver->ob;
+                               dtar->idtype= ID_OB;
                                if (idriver->name[0]) // xxx... for safety
                                        BLI_strncpy(dtar->pchan_name, idriver->name+DRIVER_NAME_OFFS, sizeof(dtar->pchan_name));
                        }
                                if (idriver->name[0]) // xxx... for safety
                                        BLI_strncpy(dtar->pchan_name, idriver->name+DRIVER_NAME_OFFS, sizeof(dtar->pchan_name));
                        }
@@ -1049,6 +1051,7 @@ static ChannelDriver *idriver_to_cdriver (IpoDriver *idriver)
                                /* only requires a single target */
                                dtar= &dvar->targets[0];
                                dtar->id= (ID *)idriver->ob;
                                /* only requires a single target */
                                dtar= &dvar->targets[0];
                                dtar->id= (ID *)idriver->ob;
+                               dtar->idtype= ID_OB;
                                if (idriver->name[0])
                                        BLI_strncpy(dtar->pchan_name, idriver->name, sizeof(dtar->pchan_name));
                                dtar->transChan= adrcode_to_dtar_transchan(idriver->adrcode);
                                if (idriver->name[0])
                                        BLI_strncpy(dtar->pchan_name, idriver->name, sizeof(dtar->pchan_name));
                                dtar->transChan= adrcode_to_dtar_transchan(idriver->adrcode);
@@ -1063,6 +1066,7 @@ static ChannelDriver *idriver_to_cdriver (IpoDriver *idriver)
                                /* only requires single target */
                        dtar= &dvar->targets[0];
                        dtar->id= (ID *)idriver->ob;
                                /* only requires single target */
                        dtar= &dvar->targets[0];
                        dtar->id= (ID *)idriver->ob;
+                       dtar->idtype= ID_OB;
                        dtar->transChan= adrcode_to_dtar_transchan(idriver->adrcode);
                }
        }
                        dtar->transChan= adrcode_to_dtar_transchan(idriver->adrcode);
                }
        }
@@ -1103,7 +1107,7 @@ static void fcurve_add_to_list (ListBase *groups, ListBase *list, FCurve *fcu, c
                                agrp->flag = AGRP_SELECTED;
                                if (muteipo) agrp->flag |= AGRP_MUTED;
                                
                                agrp->flag = AGRP_SELECTED;
                                if (muteipo) agrp->flag |= AGRP_MUTED;
                                
-                               strncpy(agrp->name, grpname, sizeof(agrp->name));
+                               BLI_strncpy(agrp->name, grpname, sizeof(agrp->name));
                                
                                BLI_addtail(&tmp_act.groups, agrp);
                                BLI_uniquename(&tmp_act.groups, agrp, "Group", '.', offsetof(bActionGroup, name), sizeof(agrp->name));
                                
                                BLI_addtail(&tmp_act.groups, agrp);
                                BLI_uniquename(&tmp_act.groups, agrp, "Group", '.', offsetof(bActionGroup, name), sizeof(agrp->name));