Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2011-08-30 14:07:50 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2011-08-30 14:07:50 +0400
commitb3704f45c4e165618e898b5b7d1a7391ad14dc50 (patch)
treeede24044252d222084cc59cef98e28ebfe8494c3 /source/blender/blenkernel/intern
parent27ec8d5043f544685001aab3552b9b4b56bc1e1a (diff)
Fixes for snprintf usage:
* 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
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r--source/blender/blenkernel/intern/particle_system.c11
-rw-r--r--source/blender/blenkernel/intern/pointcache.c20
-rw-r--r--source/blender/blenkernel/intern/report.c6
-rw-r--r--source/blender/blenkernel/intern/sequencer.c13
-rw-r--r--source/blender/blenkernel/intern/unit.c11
-rw-r--r--source/blender/blenkernel/intern/writeffmpeg.c6
6 files changed, 24 insertions, 43 deletions
diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index f62ba2be193..e1ea6e419d3 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -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"
@@ -104,12 +105,6 @@
#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);
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index 0f0afe30392..a56010a5ccf 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -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);
diff --git a/source/blender/blenkernel/intern/report.c b/source/blender/blenkernel/intern/report.c
index f84d98a31b4..4926edaeec2 100644
--- a/source/blender/blenkernel/intern/report.c
+++ b/source/blender/blenkernel/intern/report.c
@@ -44,12 +44,6 @@
#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) {
diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c
index 40e02d65323..9ef30bdd49b 100644
--- a/source/blender/blenkernel/intern/sequencer.c
+++ b/source/blender/blenkernel/intern/sequencer.c
@@ -78,11 +78,6 @@
# 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);
}
diff --git a/source/blender/blenkernel/intern/unit.c b/source/blender/blenkernel/intern/unit.c
index a9792bc44fa..72fe1c19884 100644
--- a/source/blender/blenkernel/intern/unit.c
+++ b/source/blender/blenkernel/intern/unit.c
@@ -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;
diff --git a/source/blender/blenkernel/intern/writeffmpeg.c b/source/blender/blenkernel/intern/writeffmpeg.c
index 24e0fe95a1f..13875ff19f7 100644
--- a/source/blender/blenkernel/intern/writeffmpeg.c
+++ b/source/blender/blenkernel/intern/writeffmpeg.c
@@ -39,10 +39,6 @@
#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: