[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [39795] trunk/blender/source/blender: Fixes for snprintf usage:
Brecht Van Lommel
brechtvanlommel at pandora.be
Tue Aug 30 12:07:50 CEST 2011
Revision: 39795
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39795
Author: blendix
Date: 2011-08-30 10:07:50 +0000 (Tue, 30 Aug 2011)
Log Message:
-----------
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
Modified Paths:
--------------
trunk/blender/source/blender/blenkernel/intern/particle_system.c
trunk/blender/source/blender/blenkernel/intern/pointcache.c
trunk/blender/source/blender/blenkernel/intern/report.c
trunk/blender/source/blender/blenkernel/intern/sequencer.c
trunk/blender/source/blender/blenkernel/intern/unit.c
trunk/blender/source/blender/blenkernel/intern/writeffmpeg.c
trunk/blender/source/blender/blenlib/intern/storage.c
trunk/blender/source/blender/blenloader/intern/readfile.c
trunk/blender/source/blender/editors/physics/physics_fluid.c
trunk/blender/source/blender/editors/space_console/space_console.c
trunk/blender/source/blender/editors/space_nla/nla_draw.c
trunk/blender/source/blender/gpu/intern/gpu_codegen.c
trunk/blender/source/blender/python/intern/bpy_rna.c
Modified: trunk/blender/source/blender/blenkernel/intern/particle_system.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/particle_system.c 2011-08-30 09:50:31 UTC (rev 39794)
+++ trunk/blender/source/blender/blenkernel/intern/particle_system.c 2011-08-30 10:07:50 UTC (rev 39795)
@@ -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 @@
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 @@
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);
Modified: trunk/blender/source/blender/blenkernel/intern/pointcache.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/pointcache.c 2011-08-30 09:50:31 UTC (rev 39794)
+++ trunk/blender/source/blender/blenkernel/intern/pointcache.c 2011-08-30 10:07:50 UTC (rev 39795)
@@ -917,14 +917,14 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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);
Modified: trunk/blender/source/blender/blenkernel/intern/report.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/report.c 2011-08-30 09:50:31 UTC (rev 39794)
+++ trunk/blender/source/blender/blenkernel/intern/report.c 2011-08-30 10:07:50 UTC (rev 39795)
@@ -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) {
Modified: trunk/blender/source/blender/blenkernel/intern/sequencer.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/sequencer.c 2011-08-30 09:50:31 UTC (rev 39794)
+++ trunk/blender/source/blender/blenkernel/intern/sequencer.c 2011-08-30 10:07:50 UTC (rev 39795)
@@ -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 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 @@
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 @@
/* 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);
}
Modified: trunk/blender/source/blender/blenkernel/intern/unit.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/unit.c 2011-08-30 09:50:31 UTC (rev 39794)
+++ trunk/blender/source/blender/blenkernel/intern/unit.c 2011-08-30 10:07:50 UTC (rev 39795)
@@ -34,6 +34,7 @@
#include "BKE_unit.h"
#include "BLI_math.h"
+#include "BLI_string.h"
#include "BLI_winstuff.h"
@@ -344,7 +345,7 @@
/* 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 @@
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 @@
/* 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 @@
/* 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;
Modified: trunk/blender/source/blender/blenkernel/intern/writeffmpeg.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/writeffmpeg.c 2011-08-30 09:50:31 UTC (rev 39794)
+++ trunk/blender/source/blender/blenkernel/intern/writeffmpeg.c 2011-08-30 10:07:50 UTC (rev 39795)
@@ -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 @@
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:
Modified: trunk/blender/source/blender/blenlib/intern/storage.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/storage.c 2011-08-30 09:50:31 UTC (rev 39794)
+++ trunk/blender/source/blender/blenlib/intern/storage.c 2011-08-30 10:07:50 UTC (rev 39795)
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list