fix for more warnings.
authorCampbell Barton <ideasman42@gmail.com>
Sat, 12 Feb 2011 16:54:24 +0000 (16:54 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 12 Feb 2011 16:54:24 +0000 (16:54 +0000)
- modifier code was using sizeof() without knowing the sizeof the array when clearing the modifier type array.
- use BLI_snprintf rather then sprintf where the size of the string is known.
- particle drawing code kept a reference to stack float values (not a problem at the moment but would crash if accessed later).

21 files changed:
intern/guardedalloc/intern/mallocn.c
source/blender/blenkernel/intern/blender.c
source/blender/blenkernel/intern/deform.c
source/blender/blenkernel/intern/image.c
source/blender/blenkernel/intern/library.c
source/blender/blenkernel/intern/modifier.c
source/blender/blenlib/intern/fileops.c
source/blender/editors/animation/anim_markers.c
source/blender/editors/interface/interface_regions.c
source/blender/editors/space_image/image_draw.c
source/blender/editors/space_info/info_stats.c
source/blender/editors/space_view3d/drawobject.c
source/blender/imbuf/intern/thumbs.c
source/blender/makesrna/intern/rna_access.c
source/blender/modifiers/intern/MOD_util.c
source/blender/python/generic/mathutils_matrix.c
source/blender/render/intern/source/pipeline.c
source/blender/render/intern/source/volume_precache.c
source/blender/windowmanager/intern/wm_files.c
source/blender/windowmanager/intern/wm_window.c
source/creator/creator.c

index 83aceb1..2717043 100644 (file)
@@ -167,12 +167,13 @@ static int malloc_debug_memset= 0;
 
 static void print_error(const char *str, ...)
 {
-       char buf[1024];
+       char buf[512];
        va_list ap;
 
        va_start(ap, str);
-       vsprintf(buf, str, ap);
+       vsnprintf(buf, sizeof(buf), str, ap);
        va_end(ap);
+       buf[sizeof(buf) - 1] = '\0';
 
        if (error_callback) error_callback(buf);
 }
index 6e08df0..222d416 100644 (file)
@@ -124,9 +124,9 @@ void initglobals(void)
        ENDIAN_ORDER= (((char*)&ENDIAN_ORDER)[0])? L_ENDIAN: B_ENDIAN;
 
        if(BLENDER_SUBVERSION)
-               sprintf(versionstr, "www.blender.org %d.%d", BLENDER_VERSION, BLENDER_SUBVERSION);
+               BLI_snprintf(versionstr, sizeof(versionstr), "www.blender.org %d.%d", BLENDER_VERSION, BLENDER_SUBVERSION);
        else
-               sprintf(versionstr, "www.blender.org %d", BLENDER_VERSION);
+               BLI_snprintf(versionstr, sizeof(versionstr), "www.blender.org %d", BLENDER_VERSION);
 
 #ifdef _WIN32  // FULLSCREEN
        G.windowstate = G_WINDOWSTATE_USERDEF;
@@ -314,7 +314,7 @@ static int handle_subversion_warning(Main *main)
                
                char str[128];
                
-               sprintf(str, "File written by newer Blender binary: %d.%d , expect loss of data!", main->minversionfile, main->minsubversionfile);
+               BLI_snprintf(str, sizeof(str), "File written by newer Blender binary: %d.%d , expect loss of data!", main->minversionfile, main->minsubversionfile);
 // XXX         error(str);
        }
        return 1;
@@ -520,7 +520,7 @@ void BKE_write_undo(bContext *C, const char *name)
                counter++;
                counter= counter % U.undosteps; 
        
-               sprintf(numstr, "%d.blend", counter);
+               BLI_snprintf(numstr, sizeof(numstr), "%d.blend", counter);
                BLI_make_file_string("/", tstr, btempdir, numstr);
        
                success= BLO_write_file(CTX_data_main(C), tstr, G.fileflags, NULL, NULL);
index 937681f..1b63e4f 100644 (file)
@@ -339,10 +339,10 @@ void defgroup_unique_name (bDeformGroup *dg, Object *ob)
 void flip_side_name (char *name, const char *from_name, int strip_number)
 {
        int     len;
-       char    prefix[sizeof(((bDeformGroup *)NULL)->name)]= {""};   /* The part before the facing */
-       char    suffix[sizeof(((bDeformGroup *)NULL)->name)]= {""};   /* The part after the facing */
-       char    replace[sizeof(((bDeformGroup *)NULL)->name)]=  {""};  /* The replacement string */
-       char    number[sizeof(((bDeformGroup *)NULL)->name)]=  {""};   /* The number extension string */
+       char    prefix[sizeof(((bDeformGroup *)NULL)->name)]=  "";   /* The part before the facing */
+       char    suffix[sizeof(((bDeformGroup *)NULL)->name)]=  "";   /* The part after the facing */
+       char    replace[sizeof(((bDeformGroup *)NULL)->name)]= "";   /* The replacement string */
+       char    number[sizeof(((bDeformGroup *)NULL)->name)]=  "";   /* The number extension string */
        char    *index=NULL;
 
        len= strlen(from_name);
index 37d1e65..4092abb 100644 (file)
@@ -873,32 +873,23 @@ static void stampdata(Scene *scene, StampData *stamp_data, int do_prefix)
        time_t t;
 
        if (scene->r.stamp & R_STAMP_FILENAME) {
-               if (G.relbase_valid) {
-                       if (do_prefix)          sprintf(stamp_data->file, "File %s", G.main->name);
-                       else                            sprintf(stamp_data->file, "%s", G.main->name);
-               } else {
-                       if (do_prefix)          strcpy(stamp_data->file, "File <untitled>");
-                       else                            strcpy(stamp_data->file, "<untitled>");
-               }
+               BLI_snprintf(stamp_data->file, sizeof(stamp_data->file), do_prefix ? "File %s":"%s", G.relbase_valid ? G.main->name:"<untitled>");
        } else {
                stamp_data->file[0] = '\0';
        }
        
        if (scene->r.stamp & R_STAMP_NOTE) {
                /* Never do prefix for Note */
-               sprintf(stamp_data->note, "%s", scene->r.stamp_udata);
+               BLI_snprintf(stamp_data->note, sizeof(stamp_data->note), "%s", scene->r.stamp_udata);
        } else {
                stamp_data->note[0] = '\0';
        }
        
        if (scene->r.stamp & R_STAMP_DATE) {
-
-               t = time (NULL);
-               tl = localtime (&t);
-               sprintf (text, "%04d/%02d/%02d %02d:%02d:%02d", tl->tm_year+1900, tl->tm_mon+1, tl->tm_mday, tl->tm_hour, tl->tm_min, tl->tm_sec);
-
-               if (do_prefix)          sprintf(stamp_data->date, "Date %s", text);
-               else                            sprintf(stamp_data->date, "%s", text);
+               t = time(NULL);
+               tl = localtime(&t);
+               BLI_snprintf(text, sizeof(text), "%04d/%02d/%02d %02d:%02d:%02d", tl->tm_year+1900, tl->tm_mon+1, tl->tm_mday, tl->tm_hour, tl->tm_min, tl->tm_sec);
+               BLI_snprintf(stamp_data->date, sizeof(stamp_data->date), do_prefix ? "Date %s":"%s", text);
        } else {
                stamp_data->date[0] = '\0';
        }
@@ -908,9 +899,8 @@ static void stampdata(Scene *scene, StampData *stamp_data, int do_prefix)
        
                if (name)       strcpy(text, name);
                else            strcpy(text, "<none>");
-               
-               if (do_prefix)          sprintf(stamp_data->marker, "Marker %s", text);
-               else                            sprintf(stamp_data->marker, "%s", text);
+
+               BLI_snprintf(stamp_data->marker, sizeof(stamp_data->marker), do_prefix ? "Marker %s":"%s", text);
        } else {
                stamp_data->marker[0] = '\0';
        }
@@ -932,12 +922,11 @@ static void stampdata(Scene *scene, StampData *stamp_data, int do_prefix)
                }
 
                if (scene->r.frs_sec < 100)
-                       sprintf (text, "%02d:%02d:%02d.%02d", h, m, s, f);
+                       BLI_snprintf(text, sizeof(text), "%02d:%02d:%02d.%02d", h, m, s, f);
                else
-                       sprintf (text, "%02d:%02d:%02d.%03d", h, m, s, f);
-               
-               if (do_prefix)          sprintf(stamp_data->time, "Time %s", text);
-               else                            sprintf(stamp_data->time, "%s", text);
+                       BLI_snprintf(text, sizeof(text), "%02d:%02d:%02d.%03d", h, m, s, f);
+
+               BLI_snprintf(stamp_data->time, sizeof(stamp_data->time), do_prefix ? "Time %s":"%s", text);
        } else {
                stamp_data->time[0] = '\0';
        }
@@ -948,39 +937,32 @@ static void stampdata(Scene *scene, StampData *stamp_data, int do_prefix)
                
                if(scene->r.efra>9)
                        digits= 1 + (int) log10(scene->r.efra);
-               
-               if (do_prefix)          sprintf(format, "Frame %%0%di", digits);
-               else                            sprintf(format, "%%0%di", digits);
-               sprintf (stamp_data->frame, format, scene->r.cfra);
+
+               BLI_snprintf(format, sizeof(format), do_prefix ? "Frame %%0%di":"%%0%di", digits);
+               BLI_snprintf (stamp_data->frame, sizeof(stamp_data->frame), format, scene->r.cfra);
        } else {
                stamp_data->frame[0] = '\0';
        }
 
        if (scene->r.stamp & R_STAMP_CAMERA) {
-               if (scene->camera) strcpy(text, scene->camera->id.name+2);
-               else            strcpy(text, "<none>");
-               
-               if (do_prefix)          sprintf(stamp_data->camera, "Camera %s", text);
-               else                            sprintf(stamp_data->camera, "%s", text);
+               BLI_snprintf(stamp_data->camera, sizeof(stamp_data->camera), do_prefix ? "Camera %s":"%s", scene->camera ? scene->camera->id.name+2 : "<none>");
        } else {
                stamp_data->camera[0] = '\0';
        }
 
        if (scene->r.stamp & R_STAMP_CAMERALENS) {
                if (scene->camera && scene->camera->type == OB_CAMERA) {
-                       sprintf(text, "%.2f", ((Camera *)scene->camera->data)->lens);
+                       BLI_snprintf(text, sizeof(text), "%.2f", ((Camera *)scene->camera->data)->lens);
                }
                else            strcpy(text, "<none>");
 
-               if (do_prefix)          sprintf(stamp_data->cameralens, "Lens %s", text);
-               else                            sprintf(stamp_data->cameralens, "%s", text);
+               BLI_snprintf(stamp_data->cameralens, sizeof(stamp_data->cameralens), do_prefix ? "Lens %s":"%s", text);
        } else {
                stamp_data->cameralens[0] = '\0';
        }
 
        if (scene->r.stamp & R_STAMP_SCENE) {
-               if (do_prefix)          sprintf(stamp_data->scene, "Scene %s", scene->id.name+2);
-               else                            sprintf(stamp_data->scene, "%s", scene->id.name+2);
+               BLI_snprintf(stamp_data->scene, sizeof(stamp_data->scene), do_prefix ? "Scene %s":"%s", scene->id.name+2);
        } else {
                stamp_data->scene[0] = '\0';
        }
@@ -990,9 +972,8 @@ static void stampdata(Scene *scene, StampData *stamp_data, int do_prefix)
        
                if (seq) strcpy(text, seq->name+2);
                else            strcpy(text, "<none>");
-               
-               if (do_prefix)          sprintf(stamp_data->strip, "Strip %s", text);
-               else                            sprintf(stamp_data->strip, "%s", text);
+
+               BLI_snprintf(stamp_data->strip, sizeof(stamp_data->strip), do_prefix ? "Strip %s":"%s", text);
        } else {
                stamp_data->strip[0] = '\0';
        }
@@ -1004,8 +985,7 @@ static void stampdata(Scene *scene, StampData *stamp_data, int do_prefix)
                if (stats && (scene->r.stamp & R_STAMP_RENDERTIME)) {
                        BLI_timestr(stats->lastframetime, text);
 
-                       if (do_prefix)          sprintf(stamp_data->rendertime, "RenderTime %s", text);
-                       else                            sprintf(stamp_data->rendertime, "%s", text);
+                       BLI_snprintf(stamp_data->rendertime, sizeof(stamp_data->rendertime), do_prefix ? "RenderTime %s":"%s", text);
                } else {
                        stamp_data->rendertime[0] = '\0';
                }
index 6eb5399..671f4d9 100644 (file)
@@ -920,7 +920,7 @@ static void IDnames_to_dyn_pupstring(DynStr *pupds, ListBase *lb, ID *link, shor
                                
                        BLI_dynstr_append(pupds, buf);
                        BLI_dynstr_append(pupds, id->name+2);
-                       sprintf(buf, "%%x%d", i+1);
+                       BLI_snprintf(buf, sizeof(buf), "%%x%d", i+1);
                        BLI_dynstr_append(pupds, buf);
                        
                        /* icon */
@@ -931,7 +931,7 @@ static void IDnames_to_dyn_pupstring(DynStr *pupds, ListBase *lb, ID *link, shor
                        case ID_IM: /* fall through */
                        case ID_WO: /* fall through */
                        case ID_LA: /* fall through */
-                               sprintf(buf, "%%i%d", BKE_icon_getid(id) );
+                               BLI_snprintf(buf, sizeof(buf), "%%i%d", BKE_icon_getid(id) );
                                BLI_dynstr_append(pupds, buf);
                                break;
                        default:
@@ -1128,7 +1128,7 @@ static int check_for_dupid(ListBase *lb, ID *id, char *name)
                        continue;
                }
                /* this format specifier is from hell... */
-               sprintf(name, "%s.%.3d", left, nr);
+               BLI_snprintf(name, sizeof(id->name) - 2,"%s.%.3d", left, nr);
 
                return 1;
        }
index 03091b9..6f80753 100644 (file)
@@ -57,7 +57,7 @@
 
 ModifierTypeInfo *modifierType_getInfo(ModifierType type)
 {
-       static ModifierTypeInfo *types[NUM_MODIFIER_TYPES];
+       static ModifierTypeInfo *types[NUM_MODIFIER_TYPES]= {0};
        static int types_init = 1;
 
        if (types_init) {
@@ -220,12 +220,13 @@ int modifier_sameTopology(ModifierData *md)
 
 void modifier_setError(ModifierData *md, const char *format, ...)
 {
-       char buffer[2048];
+       char buffer[512];
        va_list ap;
 
        va_start(ap, format);
-       vsprintf(buffer, format, ap);
+       vsnprintf(buffer, sizeof(buffer), format, ap);
        va_end(ap);
+       buffer[sizeof(buffer) - 1]= '\0';
 
        if (md->error)
                MEM_freeN(md->error);
index 462e3ed..5ee6522 100644 (file)
@@ -271,7 +271,7 @@ int BLI_rename(const char *from, const char *to) {
  * timer, and... We implement a callback mechanism. The system will
  * have to initialise the callback before the functions will work!
  * */
-static char str[MAXPATHLEN+12];
+static char str[12 + (MAXPATHLEN * 2)];
 
 int BLI_delete(const char *file, int dir, int recursive) 
 {
@@ -280,34 +280,34 @@ int BLI_delete(const char *file, int dir, int recursive)
        }
        else {
                if (recursive) {
-                       sprintf(str, "/bin/rm -rf \"%s\"", file);
+                       BLI_snprintf(str, sizeof(str), "/bin/rm -rf \"%s\"", file);
                        return system(str);
                }
                else if (dir) {
-                       sprintf(str, "/bin/rmdir \"%s\"", file);
+                       BLI_snprintf(str, sizeof(str), "/bin/rmdir \"%s\"", file);
                        return system(str);
                }
                else {
-                       return remove(file); //sprintf(str, "/bin/rm -f \"%s\"", file);
+                       return remove(file); //BLI_snprintf(str, sizeof(str), "/bin/rm -f \"%s\"", file);
                }
        }
        return -1;
 }
 
 int BLI_move(const char *file, const char *to) {
-       sprintf(str, "/bin/mv -f \"%s\" \"%s\"", file, to);
+       BLI_snprintf(str, sizeof(str), "/bin/mv -f \"%s\" \"%s\"", file, to);
 
        return system(str);
 }
 
 int BLI_copy_fileops(const char *file, const char *to) {
-       sprintf(str, "/bin/cp -rf \"%s\" \"%s\"", file, to);
+       BLI_snprintf(str, sizeof(str), "/bin/cp -rf \"%s\" \"%s\"", file, to);
 
        return system(str);
 }
 
 int BLI_link(const char *file, const char *to) {
-       sprintf(str, "/bin/ln -f \"%s\" \"%s\"", file, to);
+       BLI_snprintf(str, sizeof(str), "/bin/ln -f \"%s\" \"%s\"", file, to);
        
        return system(str);
 }
index 4a39534..7e9b52c 100644 (file)
@@ -519,7 +519,7 @@ static int ed_marker_add(bContext *C, wmOperator *UNUSED(op))
        marker = MEM_callocN(sizeof(TimeMarker), "TimeMarker");
        marker->flag= SELECT;
        marker->frame= frame;
-       sprintf(marker->name, "F_%02d", frame); // XXX - temp code only
+       BLI_snprintf(marker->name, sizeof(marker->name), "F_%02d", frame); // XXX - temp code only
        BLI_addtail(markers, marker);
        
        WM_event_add_notifier(C, NC_SCENE|ND_MARKERS, NULL);
@@ -747,19 +747,19 @@ static int ed_marker_move_modal(bContext *C, wmOperator *op, wmEvent *evt)
                                        if (ELEM(mm->slink->spacetype, SPACE_TIME, SPACE_SOUND)) {
                                                SpaceTime *stime= (SpaceTime *)mm->slink;
                                                if (stime->flag & TIME_DRAWFRAMES) 
-                                                       sprintf(str, "Marker %d offset %d", selmarker->frame, offs);
+                                                       BLI_snprintf(str, sizeof(str), "Marker %d offset %d", selmarker->frame, offs);
                                                else 
-                                                       sprintf(str, "Marker %.2f offset %.2f", FRA2TIME(selmarker->frame), FRA2TIME(offs));
+                                                       BLI_snprintf(str, sizeof(str), "Marker %.2f offset %.2f", FRA2TIME(selmarker->frame), FRA2TIME(offs));
                                        }
                                        else if (mm->slink->spacetype == SPACE_ACTION) {
                                                SpaceAction *saction= (SpaceAction *)mm->slink;
                                                if (saction->flag & SACTION_DRAWTIME)
-                                                       sprintf(str, "Marker %.2f offset %.2f", FRA2TIME(selmarker->frame), FRA2TIME(offs));
+                                                       BLI_snprintf(str, sizeof(str), "Marker %.2f offset %.2f", FRA2TIME(selmarker->frame), FRA2TIME(offs));
                                                else
-                                                       sprintf(str, "Marker %.2f offset %.2f", (double)(selmarker->frame), (double)(offs));
+                                                       BLI_snprintf(str, sizeof(str), "Marker %.2f offset %.2f", (double)(selmarker->frame), (double)(offs));
                                        }
                                        else {
-                                               sprintf(str, "Marker %.2f offset %.2f", (double)(selmarker->frame), (double)(offs));
+                                               BLI_snprintf(str, sizeof(str), "Marker %.2f offset %.2f", (double)(selmarker->frame), (double)(offs));
                                        }
                                }
                                else {
@@ -767,19 +767,19 @@ static int ed_marker_move_modal(bContext *C, wmOperator *op, wmEvent *evt)
                                        if (ELEM(mm->slink->spacetype, SPACE_TIME, SPACE_SOUND)) { 
                                                SpaceTime *stime= (SpaceTime *)mm->slink;
                                                if (stime->flag & TIME_DRAWFRAMES) 
-                                                       sprintf(str, "Marker offset %d ", offs);
+                                                       BLI_snprintf(str, sizeof(str), "Marker offset %d ", offs);
                                                else 
-                                                       sprintf(str, "Marker offset %.2f ", FRA2TIME(offs));
+                                                       BLI_snprintf(str, sizeof(str), "Marker offset %.2f ", FRA2TIME(offs));
                                        }
                                        else if (mm->slink->spacetype == SPACE_ACTION) {
                                                SpaceAction *saction= (SpaceAction *)mm->slink;
                                                if (saction->flag & SACTION_DRAWTIME)
-                                                       sprintf(str, "Marker offset %.2f ", FRA2TIME(offs));
+                                                       BLI_snprintf(str, sizeof(str), "Marker offset %.2f ", FRA2TIME(offs));
                                                else
-                                                       sprintf(str, "Marker offset %.2f ", (double)(offs));
+                                                       BLI_snprintf(str, sizeof(str), "Marker offset %.2f ", (double)(offs));
                                        }
                                        else {
-                                               sprintf(str, "Marker offset %.2f ", (double)(offs));
+                                               BLI_snprintf(str, sizeof(str), "Marker offset %.2f ", (double)(offs));
                                        }
                                }
                                
@@ -802,7 +802,7 @@ static int ed_marker_move_modal(bContext *C, wmOperator *op, wmEvent *evt)
                        ed_marker_move_apply(op);
                        // ed_marker_header_update(C, op, str, (int)vec[0]);
                        // strcat(str, str_tx);
-                       sprintf(str, "Marker offset %s", str_tx);
+                       BLI_snprintf(str, sizeof(str), "Marker offset %s", str_tx);
                        ED_area_headerprint(CTX_wm_area(C), str);
                        
                        WM_event_add_notifier(C, NC_SCENE|ND_MARKERS, NULL);
index e8a383d..4574c1f 100644 (file)
@@ -2295,7 +2295,8 @@ static void vconfirm_opname(bContext *C, const char *opname, const char *title,
 
        s= buf;
        if (title) s+= sprintf(s, "%s%%t|", title);
-       vsprintf(s, itemfmt, ap);
+       vsnprintf(s, sizeof(buf) - (s - buf), itemfmt, ap);
+       buf[sizeof(buf) - 1]= '\0';
 
        handle= ui_popup_menu_create(C, NULL, NULL, NULL, NULL, buf);
 
index 3932cae..0dcfa9e 100644 (file)
@@ -41,6 +41,7 @@
 #include "PIL_time.h"
 
 #include "BLI_threads.h"
+#include "BLI_string.h"
 #include "BLI_utildefines.h"
 
 #include "IMB_imbuf.h"
@@ -129,26 +130,27 @@ static void draw_render_info(Scene *scene, Image *ima, ARegion *ar)
 void draw_image_info(ARegion *ar, int channels, int x, int y, char *cp, float *fp, int *zp, float *zpf)
 {
        char str[256];
-       int ofs;
-       
-       ofs= sprintf(str, "X: %4d Y: %4d ", x, y);
+       int ofs= 0;
+
+       ofs += BLI_snprintf(str, sizeof(str)-ofs, "X: %4d Y: %4d ", x, y);
        if(cp)
-               ofs+= sprintf(str+ofs, "| R: %3d G: %3d B: %3d A: %3d ", cp[0], cp[1], cp[2], cp[3]);
+               ofs+= BLI_snprintf(str, sizeof(str)-ofs, "| R: %3d G: %3d B: %3d A: %3d ", cp[0], cp[1], cp[2], cp[3]);
 
        if(fp) {
                if(channels==4)
-                       ofs+= sprintf(str+ofs, "| R: %.3f G: %.3f B: %.3f A: %.3f ", fp[0], fp[1], fp[2], fp[3]);
+                       ofs+= BLI_snprintf(str, sizeof(str)-ofs, "| R: %.3f G: %.3f B: %.3f A: %.3f ", fp[0], fp[1], fp[2], fp[3]);
                else if(channels==1)
-                       ofs+= sprintf(str+ofs, "| Val: %.3f ", fp[0]);
+                       ofs+= BLI_snprintf(str, sizeof(str)-ofs, "| Val: %.3f ", fp[0]);
                else if(channels==3)
-                       ofs+= sprintf(str+ofs, "| R: %.3f G: %.3f B: %.3f ", fp[0], fp[1], fp[2]);
+                       ofs+= BLI_snprintf(str, sizeof(str)-ofs, "| R: %.3f G: %.3f B: %.3f ", fp[0], fp[1], fp[2]);
        }
 
        if(zp)
-               ofs+= sprintf(str+ofs, "| Z: %.4f ", 0.5+0.5*(((float)*zp)/(float)0x7fffffff));
+               ofs+= BLI_snprintf(str, sizeof(str)-ofs, "| Z: %.4f ", 0.5+0.5*(((float)*zp)/(float)0x7fffffff));
        if(zpf)
-               ofs+= sprintf(str+ofs, "| Z: %.3f ", *zpf);
-       
+               ofs+= BLI_snprintf(str, sizeof(str)-ofs, "| Z: %.3f ", *zpf);
+       (void)ofs;
+
        glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
        glEnable(GL_BLEND);
        
index cf3607e..aa5a00e 100644 (file)
@@ -368,9 +368,9 @@ static void stats_string(Scene *scene)
        mmap_in_use= MEM_get_mapped_memory_in_use();
 
        /* get memory statistics */
-       s= memstr + sprintf(memstr, " | Mem:%.2fM", ((mem_in_use-mmap_in_use)>>10)/1024.0);
+       s= memstr + sprintf(memstr, " | Mem:%.2fM", (double)((mem_in_use-mmap_in_use)>>10)/1024.0);
        if(mmap_in_use)
-               sprintf(s, " (%.2fM)", ((mmap_in_use)>>10)/1024.0);
+               sprintf(s, " (%.2fM)", (double)((mmap_in_use)>>10)/1024.0);
 
        s= stats->infostr;
 
index 8724f2f..aa35438 100644 (file)
@@ -4070,8 +4070,14 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
                psys->lattice= NULL;
        }
 
-       if( (base->flag & OB_FROMDUPLI) && (ob->flag & OB_FROMGROUP) )
+       if(pdd) {
+               /* drop references to stack memory */
+               pdd->ma_r= pdd->ma_g= pdd->ma_b= NULL;
+       }
+
+       if( (base->flag & OB_FROMDUPLI) && (ob->flag & OB_FROMGROUP) ) {
                glLoadMatrixf(rv3d->viewmat);
+       }
 }
 
 static void draw_update_ptcache_edit(Scene *scene, Object *ob, PTCacheEdit *edit)
index 8abc2e8..16411ec 100644 (file)
@@ -202,7 +202,7 @@ static int uri_from_filename( const char *path, char *uri )
        return 1;
 }
 
-static void thumbname_from_uri(const char* uri, char* thumb)
+static void thumbname_from_uri(const char* uri, char* thumb, const int thumb_len)
 {
        char hexdigest[33];
        unsigned char digest[16];
@@ -211,18 +211,18 @@ static void thumbname_from_uri(const char* uri, char* thumb)
        hexdigest[0] = '\0';
        to_hex_char(hexdigest, digest, 16);
        hexdigest[32] = '\0';
-       sprintf(thumb, "%s.png", hexdigest);
+       BLI_snprintf(thumb, thumb_len, "%s.png", hexdigest);
 }
 
-static int thumbpath_from_uri(const char* uri, char* path, ThumbSize size)
+static int thumbpath_from_uri(const char* uri, char* path, const int path_len, ThumbSize size)
 {
        char tmppath[FILE_MAX];
        int rv = 0;
 
        if (get_thumb_dir(tmppath, size)) {
                char thumb[40];
-               thumbname_from_uri(uri, thumb);
-               BLI_snprintf(path, FILE_MAX, "%s%s", tmppath, thumb);
+               thumbname_from_uri(uri, thumb, sizeof(thumb));
+               BLI_snprintf(path, path_len, "%s%s", tmppath, thumb);
                rv = 1;
        }
        return rv;
@@ -271,7 +271,7 @@ ImBuf* IMB_thumb_create(const char* path, ThumbSize size, ThumbSource source, Im
        }
 
        uri_from_filename(path, uri);
-       thumbname_from_uri(uri, thumb);
+       thumbname_from_uri(uri, thumb, sizeof(thumb));
        if (get_thumb_dir(tdir, size)) {
                BLI_snprintf(tpath, FILE_MAX, "%s%s", tdir, thumb);
                thumb[8] = '\0'; /* shorten for tempname, not needed anymore */
@@ -297,9 +297,9 @@ ImBuf* IMB_thumb_create(const char* path, ThumbSize size, ThumbSource source, Im
 
                                if (img != NULL) {
                                        stat(path, &info);
-                                       sprintf(mtime, "%ld", info.st_mtime);
-                                       sprintf(cwidth, "%d", img->x);
-                                       sprintf(cheight, "%d", img->y);
+                                       BLI_snprintf(mtime, sizeof(mtime), "%ld", info.st_mtime);
+                                       BLI_snprintf(cwidth, sizeof(cwidth), "%d", img->x);
+                                       BLI_snprintf(cheight, sizeof(cheight), "%d", img->y);
                                }
                        } else if (THB_SOURCE_MOVIE == source) {
                                struct anim * anim = NULL;
@@ -315,7 +315,7 @@ ImBuf* IMB_thumb_create(const char* path, ThumbSize size, ThumbSource source, Im
                                        IMB_free_anim(anim);
                                }
                                stat(path, &info);
-                               sprintf(mtime, "%ld", info.st_mtime);
+                               BLI_snprintf(mtime, sizeof(mtime), "%ld", info.st_mtime);
                        }
                        if (!img) return 0;             
 
@@ -332,7 +332,7 @@ ImBuf* IMB_thumb_create(const char* path, ThumbSize size, ThumbSource source, Im
                        
                        IMB_scaleImBuf(img, ex, ey);
                }
-               sprintf(desc, "Thumbnail for %s", uri);
+               BLI_snprintf(desc, sizeof(desc), "Thumbnail for %s", uri);
                IMB_metadata_change_field(img, "Description", desc);
                IMB_metadata_change_field(img, "Software", "Blender");
                IMB_metadata_change_field(img, "Thumb::URI", uri);
@@ -365,7 +365,7 @@ ImBuf* IMB_thumb_read(const char* path, ThumbSize size)
        if (!uri_from_filename(path,uri)) {
                return NULL;
        }
-       if (thumbpath_from_uri(uri, thumb, size)) {             
+       if (thumbpath_from_uri(uri, thumb, sizeof(thumb), size)) {              
                img = IMB_loadiffname(thumb, IB_rect | IB_metadata);
        }
 
@@ -381,7 +381,7 @@ void IMB_thumb_delete(const char* path, ThumbSize size)
        if (!uri_from_filename(path ,uri)) {
                return;
        }
-       if (thumbpath_from_uri(uri, thumb, size)) {
+       if (thumbpath_from_uri(uri, thumb, sizeof(thumb), size)) {
                if (strncmp(path, thumb, strlen(thumb)) == 0) {
                        return;
                }
@@ -406,14 +406,14 @@ ImBuf* IMB_thumb_manage(const char* path, ThumbSize size, ThumbSource source)
        if (!uri_from_filename(path,uri)) {
                return NULL;
        }
-       if (thumbpath_from_uri(uri, thumb, THB_FAIL)) {
+       if (thumbpath_from_uri(uri, thumb, sizeof(thumb), THB_FAIL)) {
                /* failure thumb exists, don't try recreating */
                if (BLI_exists(thumb)) {
                        return NULL;
                }
        }
 
-       if (thumbpath_from_uri(uri, thumb, size)) {
+       if (thumbpath_from_uri(uri, thumb, sizeof(thumb), size)) {
                if (strncmp(path, thumb, strlen(thumb)) == 0) {
                        img = IMB_loadiffname(path, IB_rect);
                } else {
index b8e14a9..2a3fb11 100644 (file)
@@ -3245,7 +3245,7 @@ char *RNA_path_append(const char *path, PointerRNA *ptr, PropertyRNA *prop, int
                        BLI_dynstr_append(dynstr, "\"");
                }
                else {
-                       sprintf(appendstr, "%d", intkey);
+                       BLI_snprintf(appendstr, sizeof(appendstr), "%d", intkey);
                        BLI_dynstr_append(dynstr, appendstr);
                }
 
index 036ae27..8ea7174 100644 (file)
@@ -148,7 +148,6 @@ DerivedMesh *get_dm(Object *ob, struct EditMesh *em, DerivedMesh *dm, float (*ve
 /* only called by BKE_modifier.h/modifier.c */
 void modifier_type_init(ModifierTypeInfo *types[])
 {
-       memset(types, 0, sizeof(types));
 #define INIT_TYPE(typeName) (types[eModifierType_##typeName] = &modifierType_##typeName)
        INIT_TYPE(None);
        INIT_TYPE(Curve);
index 9144da4..10b799c 100644 (file)
@@ -879,9 +879,6 @@ static char Matrix_invert_doc[] =
 "\n"
 "   Set the matrix to its inverse.\n"
 "\n"
-"   :return: an instance of itself.\n"
-"   :rtype: :class:`Matrix`\n"
-"\n"
 "   .. note:: :exc:`ValueError` exception is raised.\n"
 "\n"
 "   .. seealso:: <http://en.wikipedia.org/wiki/Inverse_matrix>\n"
index e9dd3d3..a3f9831 100644 (file)
@@ -457,9 +457,9 @@ static void scene_unique_exr_name(Scene *scene, char *str, int sample)
        BLI_splitdirstring(di, fi);
        
        if(sample==0)
-               sprintf(name, "%s_%s.exr", fi, scene->id.name+2);
+               BLI_snprintf(name, sizeof(name), "%s_%s.exr", fi, scene->id.name+2);
        else
-               sprintf(name, "%s_%s%d.exr", fi, scene->id.name+2, sample);
+               BLI_snprintf(name, sizeof(name), "%s_%s%d.exr", fi, scene->id.name+2, sample);
 
        BLI_make_file_string("/", str, btempdir, name);
 }
@@ -1597,7 +1597,7 @@ static void print_part_stats(Render *re, RenderPart *pa)
 {
        char str[64];
        
-       sprintf(str, "%s, Part %d-%d", re->scene->id.name+2, pa->nr, re->i.totpart);
+       BLI_snprintf(str, sizeof(str), "%s, Part %d-%d", re->scene->id.name+2, pa->nr, re->i.totpart);
        re->i.infostr= str;
        re->stats_draw(re->sdh, &re->i);
        re->i.infostr= NULL;
index 609e647..ddb3d68 100644 (file)
@@ -397,7 +397,7 @@ void multiple_scattering_diffusion(Render *re, VolumePrecache *vp, Material *ma)
                                        /* Displays progress every second */
                                        if(time-lasttime>1.0f) {
                                                char str[64];
-                                               sprintf(str, "Simulating multiple scattering: %d%%", (int)(100.0f * (c / total)));
+                                               BLI_snprintf(str, sizeof(str), "Simulating multiple scattering: %d%%", (int)(100.0f * (c / total)));
                                                re->i.infostr= str;
                                                re->stats_draw(re->sdh, &re->i);
                                                re->i.infostr= NULL;
@@ -742,7 +742,7 @@ void vol_precache_objectinstance_threads(Render *re, ObjectInstanceRen *obi, Mat
                time= PIL_check_seconds_timer();
                if(time-lasttime>1.0f) {
                        char str[64];
-                       sprintf(str, "Precaching volume: %d%%", (int)(100.0f * ((float)counter / (float)totparts)));
+                       BLI_snprintf(str, sizeof(str), "Precaching volume: %d%%", (int)(100.0f * ((float)counter / (float)totparts)));
                        re->i.infostr= str;
                        re->stats_draw(re->sdh, &re->i);
                        re->i.infostr= NULL;
index 644320b..8e56588 100644 (file)
@@ -543,18 +543,18 @@ static void do_history(char *name, ReportList *reports)
        if(strlen(name)<2) return;
                
        while(hisnr > 1) {
-               sprintf(tempname1, "%s%d", name, hisnr-1);
-               sprintf(tempname2, "%s%d", name, hisnr);
+               BLI_snprintf(tempname1, sizeof(tempname1), "%s%d", name, hisnr-1);
+               BLI_snprintf(tempname2, sizeof(tempname2), "%s%d", name, hisnr);
        
                if(BLI_rename(tempname1, tempname2))
                        BKE_report(reports, RPT_ERROR, "Unable to make version backup");
                        
                hisnr--;
        }
-               
+
        /* is needed when hisnr==1 */
-       sprintf(tempname1, "%s%d", name, hisnr);
-       
+       BLI_snprintf(tempname1, sizeof(tempname1), "%s%d", name, hisnr);
+
        if(BLI_rename(name, tempname1))
                BKE_report(reports, RPT_ERROR, "Unable to make version backup");
 }
@@ -744,8 +744,8 @@ void wm_autosave_location(char *filename)
        char *savedir;
 #endif
 
-       sprintf(pidstr, "%d.blend", abs(getpid()));
-       
+       BLI_snprintf(pidstr, sizeof(pidstr), "%d.blend", abs(getpid()));
+
 #ifdef WIN32
        /* XXX Need to investigate how to handle default location of '/tmp/'
         * This is a relative directory on Windows, and it may be
index db427ea..9749521 100644 (file)
@@ -273,12 +273,7 @@ void wm_window_title(wmWindowManager *wm, wmWindow *win)
                /* this is set to 1 if you don't have startup.blend open */
                if(G.save_over && G.main->name[0]) {
                        char str[sizeof(G.main->name) + 12];
-                       
-                       if(wm->file_saved)
-                               sprintf(str, "Blender [%s]", G.main->name);
-                       else
-                               sprintf(str, "Blender* [%s]", G.main->name);
-                       
+                       BLI_snprintf(str, sizeof(str), "Blender%s [%s]", wm->file_saved ? "":"*", G.main->name);
                        GHOST_SetTitle(win->ghostwin, str);
                }
                else
index 730563d..215dd35 100644 (file)
@@ -932,9 +932,10 @@ static int set_addons(int argc, char **argv, void *data)
        /* workaround for scripts not getting a bpy.context.scene, causes internal errors elsewhere */
        if (argc > 1) {
 #ifdef WITH_PYTHON
-               char *str= malloc(strlen(argv[1]) + 100);
+               const int slen= strlen(argv[1]) + 10;
+               char *str= malloc(slen);
                bContext *C= data;
-               sprintf(str, "[__import__('bpy').utils.addon_enable(i) for i in '%s'.split(',')]", argv[1]);
+               BLI_snprintf(str, slen, "[__import__('bpy').utils.addon_enable(i) for i in '%s'.split(',')]", argv[1]);
                BPY_CTX_SETUP(BPY_string_exec(C, str));
                free(str);
 #else