Fixes for snprintf usage:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Tue, 30 Aug 2011 10:07:50 +0000 (10:07 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Tue, 30 Aug 2011 10:07:50 +0000 (10:07 +0000)
* replace by BLI_snprintf in various places, note _snprintf on windows
  does not properly null terminate the string.
* fix overflow in sequencer proxy code due to buffer being smaller than
  specified size.
* fix some usage of snprintf as strcpy, this is will go wrong if the
  string contains % characters.
* remove BLI_dynstr_printf function in gpu module, use BLI_dynstr_appendf

13 files changed:
source/blender/blenkernel/intern/particle_system.c
source/blender/blenkernel/intern/pointcache.c
source/blender/blenkernel/intern/report.c
source/blender/blenkernel/intern/sequencer.c
source/blender/blenkernel/intern/unit.c
source/blender/blenkernel/intern/writeffmpeg.c
source/blender/blenlib/intern/storage.c
source/blender/blenloader/intern/readfile.c
source/blender/editors/physics/physics_fluid.c
source/blender/editors/space_console/space_console.c
source/blender/editors/space_nla/nla_draw.c
source/blender/gpu/intern/gpu_codegen.c
source/blender/python/intern/bpy_rna.c

index f62ba2be19343872fc1460fa85b9a67370afb287..e1ea6e419d3d0df2c5e39b7550ee57c0b7cd97bc 100644 (file)
@@ -69,6 +69,7 @@
 #include "BLI_listbase.h"
 #include "BLI_threads.h"
 #include "BLI_storage.h" /* For _LARGEFILE64_SOURCE;  zlib needs this on some systems */
+#include "BLI_string.h"
 #include "BLI_utildefines.h"
 
 #include "BKE_main.h"
 #include <zlib.h>
 #include <string.h>
 
-#ifdef WIN32
-#ifndef snprintf
-#define snprintf _snprintf
-#endif
-#endif
-
 #endif // DISABLE_ELBEEM
 
 /************************************************/
@@ -3876,7 +3871,7 @@ static void particles_fluid_step(ParticleSimulationData *sim, int UNUSED(cfra))
 
                        gzf = gzopen(filename, "rb");
                        if (!gzf) {
-                               snprintf(debugStrBuffer,256,"readFsPartData::error - Unable to open file for reading '%s' \n", filename); 
+                               BLI_snprintf(debugStrBuffer, sizeof(debugStrBuffer),"readFsPartData::error - Unable to open file for reading '%s' \n", filename); 
                                // XXX bad level call elbeemDebugOut(debugStrBuffer);
                                return;
                        }
@@ -3937,7 +3932,7 @@ static void particles_fluid_step(ParticleSimulationData *sim, int UNUSED(cfra))
                        gzclose( gzf );
        
                        totpart = psys->totpart = activeParts;
-                       snprintf(debugStrBuffer,256,"readFsPartData::done - particles:%d, active:%d, file:%d, mask:%d  \n", psys->totpart,activeParts,fileParts,readMask);
+                       BLI_snprintf(debugStrBuffer,sizeof(debugStrBuffer),"readFsPartData::done - particles:%d, active:%d, file:%d, mask:%d  \n", psys->totpart,activeParts,fileParts,readMask);
                        // bad level call
                        // XXX elbeemDebugOut(debugStrBuffer);
                        
index 0f0afe3039229cc06c86eff1087ad51dc6887509..a56010a5ccfb95f2a527c90dc9ae3e58a9c305e1 100644 (file)
@@ -917,14 +917,14 @@ static int ptcache_path(PTCacheID *pid, char *filename)
                if (i > 6)
                        file[i-6] = '\0';
                
-               snprintf(filename, MAX_PTCACHE_PATH, "//"PTCACHE_PATH"%s", file); /* add blend file name to pointcache dir */
+               BLI_snprintf(filename, MAX_PTCACHE_PATH, "//"PTCACHE_PATH"%s", file); /* add blend file name to pointcache dir */
                BLI_path_abs(filename, blendfilename);
                return BLI_add_slash(filename); /* new strlen() */
        }
        
        /* use the temp path. this is weak but better then not using point cache at all */
        /* btempdir is assumed to exist and ALWAYS has a trailing slash */
-       snprintf(filename, MAX_PTCACHE_PATH, "%s"PTCACHE_PATH"%d", btempdir, abs(getpid()));
+       BLI_snprintf(filename, MAX_PTCACHE_PATH, "%s"PTCACHE_PATH"%d", btempdir, abs(getpid()));
        
        return BLI_add_slash(filename); /* new strlen() */
 }
@@ -948,7 +948,7 @@ static int ptcache_filename(PTCacheID *pid, char *filename, int cfra, short do_p
                idname = (pid->ob->id.name+2);
                /* convert chars to hex so they are always a valid filename */
                while('\0' != *idname) {
-                       snprintf(newname, MAX_PTCACHE_FILE, "%02X", (char)(*idname++));
+                       BLI_snprintf(newname, MAX_PTCACHE_FILE, "%02X", (char)(*idname++));
                        newname+=2;
                        len += 2;
                }
@@ -967,12 +967,12 @@ static int ptcache_filename(PTCacheID *pid, char *filename, int cfra, short do_p
 
                if(pid->cache->flag & PTCACHE_EXTERNAL) {
                        if(pid->cache->index >= 0)
-                               snprintf(newname, MAX_PTCACHE_FILE, "_%06d_%02u"PTCACHE_EXT, cfra, pid->stack_index); /* always 6 chars */
+                               BLI_snprintf(newname, MAX_PTCACHE_FILE, "_%06d_%02u"PTCACHE_EXT, cfra, pid->stack_index); /* always 6 chars */
                        else
-                               snprintf(newname, MAX_PTCACHE_FILE, "_%06d"PTCACHE_EXT, cfra); /* always 6 chars */
+                               BLI_snprintf(newname, MAX_PTCACHE_FILE, "_%06d"PTCACHE_EXT, cfra); /* always 6 chars */
                }
                else {
-                       snprintf(newname, MAX_PTCACHE_FILE, "_%06d_%02u"PTCACHE_EXT, cfra, pid->stack_index); /* always 6 chars */
+                       BLI_snprintf(newname, MAX_PTCACHE_FILE, "_%06d_%02u"PTCACHE_EXT, cfra, pid->stack_index); /* always 6 chars */
                }
                len += 16;
        }
@@ -2002,7 +2002,7 @@ void BKE_ptcache_id_clear(PTCacheID *pid, int mode, unsigned int cfra)
                        if (dir==NULL)
                                return;
 
-                       snprintf(ext, sizeof(ext), "_%02u"PTCACHE_EXT, pid->stack_index);
+                       BLI_snprintf(ext, sizeof(ext), "_%02u"PTCACHE_EXT, pid->stack_index);
                        
                        while ((de = readdir(dir)) != NULL) {
                                if (strstr(de->d_name, ext)) { /* do we have the right extension?*/
@@ -2204,7 +2204,7 @@ void BKE_ptcache_id_time(PTCacheID *pid, Scene *scene, float cfra, int *startfra
                        if (dir==NULL)
                                return;
 
-                       snprintf(ext, sizeof(ext), "_%02u"PTCACHE_EXT, pid->stack_index);
+                       BLI_snprintf(ext, sizeof(ext), "_%02u"PTCACHE_EXT, pid->stack_index);
                        
                        while ((de = readdir(dir)) != NULL) {
                                if (strstr(de->d_name, ext)) { /* do we have the right extension?*/
@@ -2904,7 +2904,7 @@ void BKE_ptcache_disk_cache_rename(PTCacheID *pid, char *from, char *to)
                return;
        }
 
-       snprintf(ext, sizeof(ext), "_%02u"PTCACHE_EXT, pid->stack_index);
+       BLI_snprintf(ext, sizeof(ext), "_%02u"PTCACHE_EXT, pid->stack_index);
 
        /* put new name into cache */
        strcpy(pid->cache->name, to);
@@ -2960,7 +2960,7 @@ void BKE_ptcache_load_external(PTCacheID *pid)
                return;
 
        if(cache->index >= 0)
-               snprintf(ext, sizeof(ext), "_%02d"PTCACHE_EXT, cache->index);
+               BLI_snprintf(ext, sizeof(ext), "_%02d"PTCACHE_EXT, cache->index);
        else
                strcpy(ext, PTCACHE_EXT);
        
index f84d98a31b47d59bdf99dc3fef032d2c371ff56b..4926edaeec2b27c717b327ced68cb51e2b0223c6 100644 (file)
 #include <stdio.h>
 #include <string.h>
 
-#ifdef _WIN32
-#ifndef vsnprintf
-#define vsnprintf _vsnprintf
-#endif
-#endif
-
 static const char *report_type_str(int type)
 {
        switch(type) {
index 40e02d65323081426a162caf78695126ce00ba73..9ef30bdd49bdde5b7545548be6b7c050a61cd83f 100644 (file)
 #  include "AUD_C-API.h"
 #endif
 
-#ifdef WIN32
-#define snprintf _snprintf
-#endif
-
-
 static ImBuf* seq_render_strip_stack( 
        SeqRenderData context, ListBase *seqbasep, float cfra, int chanshown);
 
@@ -1193,7 +1188,7 @@ static void seq_open_anim_file(Sequence * seq)
 static int seq_proxy_get_fname(SeqRenderData context, Sequence * seq, int cfra, char * name)
 {
        int frameno;
-       char dir[FILE_MAXDIR];
+       char dir[PROXY_MAXFILE];
        int render_size = context.preview_render_size;
 
        if (!seq->strip->proxy) {
@@ -1211,7 +1206,7 @@ static int seq_proxy_get_fname(SeqRenderData context, Sequence * seq, int cfra,
        if (seq->flag & (SEQ_USE_PROXY_CUSTOM_DIR|SEQ_USE_PROXY_CUSTOM_FILE)) {
                strcpy(dir, seq->strip->proxy->dir);
        } else if (seq->type == SEQ_IMAGE) {
-               snprintf(dir, PROXY_MAXFILE, "%s/BL_proxy", seq->strip->dir);
+               BLI_snprintf(dir, PROXY_MAXFILE, "%s/BL_proxy", seq->strip->dir);
        } else {
                return FALSE;
        }
@@ -1232,14 +1227,14 @@ static int seq_proxy_get_fname(SeqRenderData context, Sequence * seq, int cfra,
        /* generate a separate proxy directory for each preview size */
 
        if (seq->type == SEQ_IMAGE) {
-               snprintf(name, PROXY_MAXFILE, "%s/images/%d/%s_proxy", dir,
+               BLI_snprintf(name, PROXY_MAXFILE, "%s/images/%d/%s_proxy", dir,
                         context.preview_render_size, 
                         give_stripelem(seq, cfra)->name);
                frameno = 1;
        } else {
                frameno = (int) give_stripelem_index(seq, cfra) 
                        + seq->anim_startofs;
-               snprintf(name, PROXY_MAXFILE, "%s/proxy_misc/%d/####", dir, 
+               BLI_snprintf(name, PROXY_MAXFILE, "%s/proxy_misc/%d/####", dir, 
                         context.preview_render_size);
        }
 
index a9792bc44fac1d041d0d44222904670ffea1a6ab..72fe1c19884e82e2dd52ae8ae5b845cbbcd283da 100644 (file)
@@ -34,6 +34,7 @@
 #include "BKE_unit.h"
 
 #include "BLI_math.h"
+#include "BLI_string.h"
 #include "BLI_winstuff.h"
 
 
@@ -344,7 +345,7 @@ static int unit_as_string(char *str, int len_max, double value, int prec, bUnitC
 
        /* Convert to a string */
        {
-               len= snprintf(str, len_max, "%.*lf", prec, value_conv);
+               len= BLI_snprintf(str, len_max, "%.*lf", prec, value_conv);
 
                if(len >= len_max)
                        len= len_max;
@@ -495,7 +496,7 @@ static int unit_scale_str(char *str, int len_max, char *str_tmp, double scale_pr
 
                len_name = strlen(replace_str);
                len_move= (len - (found_ofs+len_name)) + 1; /* 1+ to copy the string terminator */
-               len_num= snprintf(str_tmp, TEMP_STR_SIZE, "*%lg"SEP_STR, unit->scalar/scale_pref); /* # removed later */
+               len_num= BLI_snprintf(str_tmp, TEMP_STR_SIZE, "*%lg"SEP_STR, unit->scalar/scale_pref); /* # removed later */
 
                if(len_num > len_max)
                        len_num= len_max;
@@ -629,12 +630,12 @@ int bUnit_ReplaceString(char *str, int len_max, char *str_prev, double scale_pre
 
 
                /* add the unit prefix and re-run, use brackets incase there was an expression given */
-               if(snprintf(str_tmp, sizeof(str_tmp), "(%s)%s", str, unit->name) < sizeof(str_tmp)) {
+               if(BLI_snprintf(str_tmp, sizeof(str_tmp), "(%s)%s", str, unit->name) < sizeof(str_tmp)) {
                        strncpy(str, str_tmp, len_max);
                        return bUnit_ReplaceString(str, len_max, NULL, scale_pref, system, type);
                }
                else {
-                       /* snprintf would not fit into str_tmp, cant do much in this case
+                       /* BLI_snprintf would not fit into str_tmp, cant do much in this case
                         * check for this because otherwise bUnit_ReplaceString could call its self forever */
                        return 0;
                }
@@ -705,7 +706,7 @@ void bUnit_ToUnitAltName(char *str, int len_max, char *orig_str, int system, int
 
                                /* print the alt_name */
                                if(unit->name_alt)
-                                       len_name= snprintf(str, len_max, "%s", unit->name_alt);
+                                       len_name= BLI_snprintf(str, len_max, "%s", unit->name_alt);
                                else
                                        len_name= 0;
 
index 24e0fe95a1f5850c627062e8779fb852987a1ac1..13875ff19f7bc6a8cf20ce7bf4f838d7ac7d6462 100644 (file)
 #include <libswscale/swscale.h>
 #include <libavcodec/opt.h>
 
-#if defined(WIN32) && (!(defined snprintf))
-#define snprintf _snprintf
-#endif
-
 #include "MEM_guardedalloc.h"
 
 #include "DNA_scene_types.h"
@@ -652,7 +648,7 @@ static int start_ffmpeg_impl(struct RenderData *rd, int rectx, int recty, Report
 
        fmt->audio_codec = ffmpeg_audio_codec;
 
-       snprintf(of->filename, sizeof(of->filename), "%s", name);
+       BLI_snprintf(of->filename, sizeof(of->filename), "%s", name);
        /* set the codec to the user's selection */
        switch(ffmpeg_type) {
        case FFMPEG_AVI:
index 41eedef8835e9bfb748b8a09baac41f8bf6f3c75..67e27063fd0a5b19f5145021bb21622070057d66 100644 (file)
@@ -338,7 +338,7 @@ void BLI_adddirstrings(void)
                        if ( pwuser ) {
                                BLI_strncpy(file->owner, pwuser->pw_name, sizeof(file->owner));
                        } else {
-                               snprintf(file->owner, sizeof(file->owner), "%d", file->s.st_uid);
+                               BLI_snprintf(file->owner, sizeof(file->owner), "%d", file->s.st_uid);
                        }
                }
 #endif
index 4a86de51d9cefd51c00cbe084080f5e8d9ffa8d3..363e98d7a4b3ffd66202f1fc9f438e3daa13f3b7 100644 (file)
@@ -10081,7 +10081,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                           !(seq->flag & SEQ_USE_PROXY_CUSTOM_DIR))
                                        {
                                                
-                                               snprintf(seq->strip->proxy->dir, 
+                                               BLI_snprintf(seq->strip->proxy->dir, 
                                                         FILE_MAXDIR, "%s/BL_proxy", 
                                                         seq->strip->dir);
                                        }
index 37309f1e07c7f5ec659dd7c81dd09081484bc659..bd53de20871062a3bb5df132d931c5186603d504 100644 (file)
 #include <string.h>
 #include <sys/stat.h>
 
-#ifdef WIN32   /* Windos */
-#ifndef snprintf
-#define snprintf _snprintf
-#endif
-#endif
-
 #include "MEM_guardedalloc.h"
 
 /* types */
@@ -155,8 +149,8 @@ static int fluid_is_animated_mesh(FluidsimSettings *fss)
 #if 0
 /* helper function */
 void fluidsimGetGeometryObjFilename(Object *ob, char *dst) { //, char *srcname) {
-       //snprintf(dst,FILE_MAXFILE, "%s_cfgdata_%s.bobj.gz", srcname, ob->id.name);
-       snprintf(dst,FILE_MAXFILE, "fluidcfgdata_%s.bobj.gz", ob->id.name);
+       //BLI_snprintf(dst,FILE_MAXFILE, "%s_cfgdata_%s.bobj.gz", srcname, ob->id.name);
+       BLI_snprintf(dst,FILE_MAXFILE, "fluidcfgdata_%s.bobj.gz", ob->id.name);
 }
 #endif
 
@@ -888,7 +882,7 @@ static int fluidsimBake(bContext *C, ReportList *reports, Object *fsDomain)
        if(getenv(strEnvName)) {
                int dlevel = atoi(getenv(strEnvName));
                elbeemSetDebugLevel(dlevel);
-               snprintf(debugStrBuffer,256,"fluidsimBake::msg: Debug messages activated due to envvar '%s'\n",strEnvName); 
+               BLI_snprintf(debugStrBuffer,256,"fluidsimBake::msg: Debug messages activated due to envvar '%s'\n",strEnvName); 
                elbeemDebugOut(debugStrBuffer);
        }
        
@@ -925,7 +919,7 @@ static int fluidsimBake(bContext *C, ReportList *reports, Object *fsDomain)
        
        /* rough check of settings... */
        if(domainSettings->previewresxyz > domainSettings->resolutionxyz) {
-               snprintf(debugStrBuffer,256,"fluidsimBake::warning - Preview (%d) >= Resolution (%d)... setting equal.\n", domainSettings->previewresxyz ,  domainSettings->resolutionxyz); 
+               BLI_snprintf(debugStrBuffer,256,"fluidsimBake::warning - Preview (%d) >= Resolution (%d)... setting equal.\n", domainSettings->previewresxyz ,  domainSettings->resolutionxyz); 
                elbeemDebugOut(debugStrBuffer);
                domainSettings->previewresxyz = domainSettings->resolutionxyz;
        }
@@ -945,7 +939,7 @@ static int fluidsimBake(bContext *C, ReportList *reports, Object *fsDomain)
        } else {
                gridlevels = domainSettings->maxRefine;
        }
-       snprintf(debugStrBuffer,256,"fluidsimBake::msg: Baking %s, refine: %d\n", fsDomain->id.name , gridlevels ); 
+       BLI_snprintf(debugStrBuffer,256,"fluidsimBake::msg: Baking %s, refine: %d\n", fsDomain->id.name , gridlevels ); 
        elbeemDebugOut(debugStrBuffer);
        
        
@@ -997,7 +991,7 @@ static int fluidsimBake(bContext *C, ReportList *reports, Object *fsDomain)
        /* ******** init domain object's matrix ******** */
        copy_m4_m4(domainMat, fsDomain->obmat);
        if(!invert_m4_m4(invDomMat, domainMat)) {
-               snprintf(debugStrBuffer,256,"fluidsimBake::error - Invalid obj matrix?\n"); 
+               BLI_snprintf(debugStrBuffer,256,"fluidsimBake::error - Invalid obj matrix?\n"); 
                elbeemDebugOut(debugStrBuffer);
                BKE_report(reports, RPT_ERROR, "Invalid object matrix."); 
 
index 52c5100900db0eb599d36dd138f46dc6dd86cf16..c8fa049f5eb09320872f64382f5f055f603511ad 100644 (file)
@@ -169,7 +169,7 @@ static void id_drop_copy(wmDrag *drag, wmDropBox *drop)
 
        BLI_strescape(id_esc, id->name+2, sizeof(id_esc));
 
-       snprintf(text, sizeof(text), "bpy.data.%s[\"%s\"]", BKE_idcode_to_name_plural(GS(id->name)), id_esc);
+       BLI_snprintf(text, sizeof(text), "bpy.data.%s[\"%s\"]", BKE_idcode_to_name_plural(GS(id->name)), id_esc);
 
        /* copy drag path to properties */
        RNA_string_set(drop->ptr, "text", text);
@@ -186,7 +186,7 @@ static int path_drop_poll(bContext *UNUSED(C), wmDrag *drag, wmEvent *UNUSED(eve
 static void path_drop_copy(wmDrag *drag, wmDropBox *drop)
 {
        char pathname[FILE_MAXDIR+FILE_MAXFILE+2];
-       snprintf(pathname, sizeof(pathname), "\"%s\"", drag->path);
+       BLI_snprintf(pathname, sizeof(pathname), "\"%s\"", drag->path);
        RNA_string_set(drop->ptr, "text", pathname);
 }
 
index 0583f328371209a1e1e0dfd360f19cb81999466f..0c9c7877ddcea4dde3e6fe636a4558ea8fb7178e 100644 (file)
@@ -468,10 +468,10 @@ static void nla_draw_strip_text (AnimData *adt, NlaTrack *nlt, NlaStrip *strip,
        
        /* just print the name and the range */
        if (strip->flag & NLASTRIP_FLAG_TEMP_META) {
-               sprintf(str, "%d) Temp-Meta", index);
+               BLI_snprintf(str, sizeof(str), "%d) Temp-Meta", index);
        }
        else {
-               sprintf(str, strip->name);
+               BLI_strncpy(str, strip->name, sizeof(str));
        }
        
        /* set text color - if colors (see above) are light, draw black text, otherwise draw white */
@@ -514,7 +514,7 @@ static void nla_draw_strip_frames_text(NlaTrack *UNUSED(nlt), NlaStrip *strip, V
 {
        const float ytol = 1.0f; /* small offset to vertical positioning of text, for legibility */
        const char col[4] = {220, 220, 220, 255}; /* light grey */
-       char str[16] = "";
+       char str[32] = "";
        
        
        /* Always draw times above the strip, whereas sequencer drew below + above.
@@ -524,11 +524,11 @@ static void nla_draw_strip_frames_text(NlaTrack *UNUSED(nlt), NlaStrip *strip, V
         *        while also preserving some accuracy, since we do use floats
         */
                /* start frame */
-       sprintf(str, "%.1f", strip->start);
+       BLI_snprintf(str, sizeof(str), "%.1f", strip->start);
        UI_view2d_text_cache_add(v2d, strip->start-1.0f, ymaxc+ytol, str, col);
        
                /* end frame */
-       sprintf(str, "%.1f", strip->end);
+       BLI_snprintf(str, sizeof(str), "%.1f", strip->end);
        UI_view2d_text_cache_add(v2d, strip->end, ymaxc+ytol, str, col);
 }
 
@@ -730,9 +730,9 @@ static void draw_nla_channel_list_gl (bAnimContext *ac, ListBase *anim_data, Vie
                                        special = ICON_ACTION;
                                        
                                        if (act)
-                                               sprintf(name, "%s", act->id.name+2);
+                                               BLI_snprintf(name, sizeof(name), "%s", act->id.name+2);
                                        else
-                                               sprintf(name, "<No Action>");
+                                               BLI_strncpy(name, "<No Action>", sizeof(name));
                                                
                                        // draw manually still
                                        doDraw= 1;
index 77498835d57b6c916f87669cd1af7731b0349b08..360f3dbf63fec0d163e9aae712fdade00ef004c6 100644 (file)
 #include <string.h>
 #include <stdarg.h>
 
-#ifdef _WIN32
-#ifndef vsnprintf
-#define vsnprintf _vsnprintf
-#endif
-#ifndef snprintf
-#define snprintf _snprintf
-#endif
-#endif
-
 extern char datatoc_gpu_shader_material_glsl[];
 extern char datatoc_gpu_shader_vertex_glsl[];
 
@@ -168,24 +159,6 @@ struct GPUPass {
        struct GPUShader *shader;
 };
 
-/* Strings utility */
-
-static void BLI_dynstr_printf(DynStr *dynstr, const char *format, ...)
-{
-       va_list args;
-       int retval;
-       char str[2048];
-
-       va_start(args, format);
-       retval = vsnprintf(str, sizeof(str), format, args);
-       va_end(args);
-
-       if (retval >= sizeof(str))
-               fprintf(stderr, "BLI_dynstr_printf: limit exceeded\n");
-       else
-               BLI_dynstr_append(dynstr, str);
-}
-
 /* GLSL code parsing for finding function definitions.
  * These are stored in a hash for lookup when creating a material. */
 
@@ -318,7 +291,7 @@ static char *gpu_generate_function_prototyps(GHash *hash)
                name = BLI_ghashIterator_getValue(ghi);
                function = BLI_ghashIterator_getValue(ghi);
 
-               BLI_dynstr_printf(ds, "void %s(", name);
+               BLI_dynstr_appendf(ds, "void %s(", name);
                for(a=0; a<function->totparam; a++) {
                        if(function->paramqual[a] == FUNCTION_QUAL_OUT)
                                BLI_dynstr_append(ds, "out ");
@@ -334,7 +307,7 @@ static char *gpu_generate_function_prototyps(GHash *hash)
                        else
                                BLI_dynstr_append(ds, GPU_DATATYPE_STR[function->paramtype[a]]);
                                
-                       //BLI_dynstr_printf(ds, " param%d", a);
+                       //BLI_dynstr_appendf(ds, " param%d", a);
                        
                        if(a != function->totparam-1)
                                BLI_dynstr_append(ds, ", ");
@@ -390,42 +363,42 @@ static void codegen_convert_datatype(DynStr *ds, int from, int to, const char *t
 {
        char name[1024];
 
-       snprintf(name, sizeof(name), "%s%d", tmp, id);
+       BLI_snprintf(name, sizeof(name), "%s%d", tmp, id);
 
        if (from == to) {
                BLI_dynstr_append(ds, name);
        }
        else if (to == GPU_FLOAT) {
                if (from == GPU_VEC4)
-                       BLI_dynstr_printf(ds, "dot(%s.rgb, vec3(0.35, 0.45, 0.2))", name);
+                       BLI_dynstr_appendf(ds, "dot(%s.rgb, vec3(0.35, 0.45, 0.2))", name);
                else if (from == GPU_VEC3)
-                       BLI_dynstr_printf(ds, "dot(%s, vec3(0.33))", name);
+                       BLI_dynstr_appendf(ds, "dot(%s, vec3(0.33))", name);
                else if (from == GPU_VEC2)
-                       BLI_dynstr_printf(ds, "%s.r", name);
+                       BLI_dynstr_appendf(ds, "%s.r", name);
        }
        else if (to == GPU_VEC2) {
                if (from == GPU_VEC4)
-                       BLI_dynstr_printf(ds, "vec2(dot(%s.rgb, vec3(0.35, 0.45, 0.2)), %s.a)", name, name);
+                       BLI_dynstr_appendf(ds, "vec2(dot(%s.rgb, vec3(0.35, 0.45, 0.2)), %s.a)", name, name);
                else if (from == GPU_VEC3)
-                       BLI_dynstr_printf(ds, "vec2(dot(%s.rgb, vec3(0.33)), 1.0)", name);
+                       BLI_dynstr_appendf(ds, "vec2(dot(%s.rgb, vec3(0.33)), 1.0)", name);
                else if (from == GPU_FLOAT)
-                       BLI_dynstr_printf(ds, "vec2(%s, 1.0)", name);
+                       BLI_dynstr_appendf(ds, "vec2(%s, 1.0)", name);
        }
        else if (to == GPU_VEC3) {
                if (from == GPU_VEC4)
-                       BLI_dynstr_printf(ds, "%s.rgb", name);
+                       BLI_dynstr_appendf(ds, "%s.rgb", name);
                else if (from == GPU_VEC2)
-                       BLI_dynstr_printf(ds, "vec3(%s.r, %s.r, %s.r)", name, name, name);
+                       BLI_dynstr_appendf(ds, "vec3(%s.r, %s.r, %s.r)", name, name, name);
                else if (from == GPU_FLOAT)
-                       BLI_dynstr_printf(ds, "vec3(%s, %s, %s)", name, name, name);
+                       BLI_dynstr_appendf(ds, "vec3(%s, %s, %s)", name, name, name);
        }
        else {
                if (from == GPU_VEC3)
-                       BLI_dynstr_printf(ds, "vec4(%s, 1.0)", name);
+                       BLI_dynstr_appendf(ds, "vec4(%s, 1.0)", name);
                else if (from == GPU_VEC2)
-                       BLI_dynstr_printf(ds, "vec4(%s.r, %s.r, %s.r, %s.g)", name, name, name, name);
+                       BLI_dynstr_appendf(ds, "vec4(%s.r, %s.r, %s.r, %s.g)", name, name, name, name);
                else if (from == GPU_FLOAT)
-                       BLI_dynstr_printf(ds, "vec4(%s, %s, %s, 1.0)", name, name, name);
+                       BLI_dynstr_appendf(ds, "vec4(%s, %s, %s, 1.0)", name, name, name);
        }
 }
 
@@ -433,10 +406,10 @@ static void codegen_print_datatype(DynStr *ds, int type, float *data)
 {
        int i;
 
-       BLI_dynstr_printf(ds, "%s(", GPU_DATATYPE_STR[type]);
+       BLI_dynstr_appendf(ds, "%s(", GPU_DATATYPE_STR[type]);
 
        for(i=0; i<type; i++) {
-               BLI_dynstr_printf(ds, "%f", data[i]);
+               BLI_dynstr_appendf(ds, "%f", data[i]);
                if(i == type-1)
                        BLI_dynstr_append(ds, ")");
                else
@@ -568,7 +541,7 @@ static void codegen_print_uniforms_functions(DynStr *ds, ListBase *nodes)
                        if ((input->source == GPU_SOURCE_TEX) || (input->source == GPU_SOURCE_TEX_PIXEL)) {
                                /* create exactly one sampler for each texture */
                                if (codegen_input_has_texture(input) && input->bindtex)
-                                       BLI_dynstr_printf(ds, "uniform %s samp%d;\n",
+                                       BLI_dynstr_appendf(ds, "uniform %s samp%d;\n",
                                                (input->textype == GPU_TEX1D)? "sampler1D":
                                                (input->textype == GPU_TEX2D)? "sampler2D": "sampler2DShadow",
                                                input->texid);
@@ -580,11 +553,11 @@ static void codegen_print_uniforms_functions(DynStr *ds, ListBase *nodes)
                                        name = GPU_builtin_name(input->builtin);
 
                                        if(gpu_str_prefix(name, "unf")) {
-                                               BLI_dynstr_printf(ds, "uniform %s %s;\n",
+                                               BLI_dynstr_appendf(ds, "uniform %s %s;\n",
                                                        GPU_DATATYPE_STR[input->type], name);
                                        }
                                        else {
-                                               BLI_dynstr_printf(ds, "varying %s %s;\n",
+                                               BLI_dynstr_appendf(ds, "varying %s %s;\n",
                                                        GPU_DATATYPE_STR[input->type], name);
                                        }
                                }
@@ -592,19 +565,19 @@ static void codegen_print_uniforms_functions(DynStr *ds, ListBase *nodes)
                        else if (input->source == GPU_SOURCE_VEC_UNIFORM) {
                                if(input->dynamicvec) {
                                        /* only create uniforms for dynamic vectors */
-                                       BLI_dynstr_printf(ds, "uniform %s unf%d;\n",
+                                       BLI_dynstr_appendf(ds, "uniform %s unf%d;\n",
                                                GPU_DATATYPE_STR[input->type], input->id);
                                }
                                else {
                                        /* for others use const so the compiler can do folding */
-                                       BLI_dynstr_printf(ds, "const %s cons%d = ",
+                                       BLI_dynstr_appendf(ds, "const %s cons%d = ",
                                                GPU_DATATYPE_STR[input->type], input->id);
                                        codegen_print_datatype(ds, input->type, input->vec);
                                        BLI_dynstr_append(ds, ";\n");
                                }
                        }
                        else if (input->source == GPU_SOURCE_ATTRIB && input->attribfirst) {
-                               BLI_dynstr_printf(ds, "varying %s var%d;\n",
+                               BLI_dynstr_appendf(ds, "varying %s var%d;\n",
                                        GPU_DATATYPE_STR[input->type], input->attribid);
                        }
                }
@@ -624,8 +597,8 @@ static void codegen_declare_tmps(DynStr *ds, ListBase *nodes)
                for (input=node->inputs.first; input; input=input->next) {
                        if (input->source == GPU_SOURCE_TEX_PIXEL) {
                                if (codegen_input_has_texture(input) && input->definetex) {
-                                       BLI_dynstr_printf(ds, "\tvec4 tex%d = texture2D(", input->texid);
-                                       BLI_dynstr_printf(ds, "samp%d, gl_TexCoord[%d].st);\n",
+                                       BLI_dynstr_appendf(ds, "\tvec4 tex%d = texture2D(", input->texid);
+                                       BLI_dynstr_appendf(ds, "samp%d, gl_TexCoord[%d].st);\n",
                                                input->texid, input->texid);
                                }
                        }
@@ -633,7 +606,7 @@ static void codegen_declare_tmps(DynStr *ds, ListBase *nodes)
 
                /* declare temporary variables for node output storage */
                for (output=node->outputs.first; output; output=output->next)
-                       BLI_dynstr_printf(ds, "\t%s tmp%d;\n",
+                       BLI_dynstr_appendf(ds, "\t%s tmp%d;\n",
                                GPU_DATATYPE_STR[output->type], output->id);
        }
 
@@ -647,13 +620,13 @@ static void codegen_call_functions(DynStr *ds, ListBase *nodes, GPUOutput *final
        GPUOutput *output;
 
        for (node=nodes->first; node; node=node->next) {
-               BLI_dynstr_printf(ds, "\t%s(", node->name);
+               BLI_dynstr_appendf(ds, "\t%s(", node->name);
                
                for (input=node->inputs.first; input; input=input->next) {
                        if (input->source == GPU_SOURCE_TEX) {
-                               BLI_dynstr_printf(ds, "samp%d", input->texid);
+                               BLI_dynstr_appendf(ds, "samp%d", input->texid);
                                if (input->link)
-                                       BLI_dynstr_printf(ds, ", gl_TexCoord[%d].st", input->texid);
+                                       BLI_dynstr_appendf(ds, ", gl_TexCoord[%d].st", input->texid);
                        }
                        else if (input->source == GPU_SOURCE_TEX_PIXEL) {
                                if (input->link && input->link->output)
@@ -664,21 +637,21 @@ static void codegen_call_functions(DynStr *ds, ListBase *nodes, GPUOutput *final
                                                "tex", input->texid);
                        }
                        else if(input->source == GPU_SOURCE_BUILTIN)
-                               BLI_dynstr_printf(ds, "%s", GPU_builtin_name(input->builtin));
+                               BLI_dynstr_appendf(ds, "%s", GPU_builtin_name(input->builtin));
                        else if(input->source == GPU_SOURCE_VEC_UNIFORM) {
                                if(input->dynamicvec)
-                                       BLI_dynstr_printf(ds, "unf%d", input->id);
+                                       BLI_dynstr_appendf(ds, "unf%d", input->id);
                                else
-                                       BLI_dynstr_printf(ds, "cons%d", input->id);
+                                       BLI_dynstr_appendf(ds, "cons%d", input->id);
                        }
                        else if (input->source == GPU_SOURCE_ATTRIB)
-                               BLI_dynstr_printf(ds, "var%d", input->attribid);
+                               BLI_dynstr_appendf(ds, "var%d", input->attribid);
 
                        BLI_dynstr_append(ds, ", ");
                }
 
                for (output=node->outputs.first; output; output=output->next) {
-                       BLI_dynstr_printf(ds, "tmp%d", output->id);
+                       BLI_dynstr_appendf(ds, "tmp%d", output->id);
                        if (output->next)
                                BLI_dynstr_append(ds, ", ");
                }
@@ -702,7 +675,7 @@ static char *code_generate_fragment(ListBase *nodes, GPUOutput *output, const ch
        codegen_print_uniforms_functions(ds, nodes);
 
        //if(G.f & G_DEBUG)
-       //      BLI_dynstr_printf(ds, "/* %s */\n", name);
+       //      BLI_dynstr_appendf(ds, "/* %s */\n", name);
 
        BLI_dynstr_append(ds, "void main(void)\n");
        BLI_dynstr_append(ds, "{\n");
@@ -731,9 +704,9 @@ static char *code_generate_vertex(ListBase *nodes)
        for (node=nodes->first; node; node=node->next) {
                for (input=node->inputs.first; input; input=input->next) {
                        if (input->source == GPU_SOURCE_ATTRIB && input->attribfirst) {
-                               BLI_dynstr_printf(ds, "attribute %s att%d;\n",
+                               BLI_dynstr_appendf(ds, "attribute %s att%d;\n",
                                        GPU_DATATYPE_STR[input->type], input->attribid);
-                               BLI_dynstr_printf(ds, "varying %s var%d;\n",
+                               BLI_dynstr_appendf(ds, "varying %s var%d;\n",
                                        GPU_DATATYPE_STR[input->type], input->attribid);
                        }
                }
@@ -747,11 +720,11 @@ static char *code_generate_vertex(ListBase *nodes)
                        if (input->source == GPU_SOURCE_ATTRIB && input->attribfirst) {
                                if(input->attribtype == CD_TANGENT) /* silly exception */
                                {
-                                       BLI_dynstr_printf(ds, "\tvar%d.xyz = normalize((gl_ModelViewMatrix * vec4(att%d.xyz, 0)).xyz);\n", input->attribid, input->attribid);
-                                       BLI_dynstr_printf(ds, "\tvar%d.w = att%d.w;\n", input->attribid, input->attribid);
+                                       BLI_dynstr_appendf(ds, "\tvar%d.xyz = normalize((gl_ModelViewMatrix * vec4(att%d.xyz, 0)).xyz);\n", input->attribid, input->attribid);
+                                       BLI_dynstr_appendf(ds, "\tvar%d.w = att%d.w;\n", input->attribid, input->attribid);
                                }
                                else
-                                       BLI_dynstr_printf(ds, "\tvar%d = att%d;\n", input->attribid, input->attribid);
+                                       BLI_dynstr_appendf(ds, "\tvar%d = att%d;\n", input->attribid, input->attribid);
                        }
 
        BLI_dynstr_append(ds, "}\n\n");
@@ -799,9 +772,9 @@ static void GPU_nodes_extract_dynamic_inputs(GPUPass *pass, ListBase *nodes)
                                continue;
 
                        if (input->ima || input->tex)
-                               snprintf(input->shadername, sizeof(input->shadername), "samp%d", input->texid);
+                               BLI_snprintf(input->shadername, sizeof(input->shadername), "samp%d", input->texid);
                        else
-                               snprintf(input->shadername, sizeof(input->shadername), "unf%d", input->id);
+                               BLI_snprintf(input->shadername, sizeof(input->shadername), "unf%d", input->id);
 
                        /* pass non-dynamic uniforms to opengl */
                        extract = 0;
index 4abcbc684e2487528f55fc98cf45fd801d77fe58..e1c38a82142f580c0b9b903bff3e7283792c055e 100644 (file)
@@ -1251,7 +1251,7 @@ static PyObject *pyrna_enum_to_py(PointerRNA *ptr, PropertyRNA *prop, int val)
 
 #if 0                  // gives python decoding errors while generating docs :(
                                char error_str[256];
-                               snprintf(error_str, sizeof(error_str), "RNA Warning: Current value \"%d\" matches no enum in '%s', '%s', '%s'", val, RNA_struct_identifier(ptr->type), ptr_name, RNA_property_identifier(prop));
+                               BLI_snprintf(error_str, sizeof(error_str), "RNA Warning: Current value \"%d\" matches no enum in '%s', '%s', '%s'", val, RNA_struct_identifier(ptr->type), ptr_name, RNA_property_identifier(prop));
                                PyErr_Warn(PyExc_RuntimeWarning, error_str);
 #endif