[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55214] trunk/blender/source/blender: Temp fix for stupid -Wformat-security issue.
Bastien Montagne
montagne29 at wanadoo.fr
Tue Mar 12 14:18:39 CET 2013
Revision: 55214
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55214
Author: mont29
Date: 2013-03-12 13:18:39 +0000 (Tue, 12 Mar 2013)
Log Message:
-----------
Temp fix for stupid -Wformat-security issue.
Also makes more use of BLI_snprintf, and makes more consistent code acrross all "header strings" generation in transform.c.
Modified Paths:
--------------
trunk/blender/source/blender/blenkernel/intern/pointcache.c
trunk/blender/source/blender/editors/space_image/image_buttons.c
trunk/blender/source/blender/editors/space_info/info_stats.c
trunk/blender/source/blender/editors/transform/transform.c
Modified: trunk/blender/source/blender/blenkernel/intern/pointcache.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/pointcache.c 2013-03-12 13:03:58 UTC (rev 55213)
+++ trunk/blender/source/blender/blenkernel/intern/pointcache.c 2013-03-12 13:18:39 UTC (rev 55214)
@@ -840,7 +840,10 @@
/* version header */
ptcache_file_read(pf, version, 1, sizeof(char) * 4);
- if (strncmp(version, DPAINT_CACHE_VERSION, 4)) {printf("Dynamic Paint: Invalid cache version: %s!\n", version); return 0;}
+ if (strncmp(version, DPAINT_CACHE_VERSION, 4)) {
+ printf("Dynamic Paint: Invalid cache version: %s!\n", version);
+ return 0;
+ }
if (surface->format != MOD_DPAINT_SURFACE_F_IMAGESEQ && surface->data) {
unsigned int data_len;
@@ -1516,7 +1519,7 @@
if (mode == 2) {
r = LzmaCompress(out, &out_len, in, in_len, //assume sizeof(char)==1....
- props, &sizeOfIt, 5, 1 << 24, 3, 0, 2, 32, 2);
+ props, &sizeOfIt, 5, 1 << 24, 3, 0, 2, 32, 2);
if (!(r == SZ_OK) || (out_len >= in_len))
compressed = 0;
Modified: trunk/blender/source/blender/editors/space_image/image_buttons.c
===================================================================
--- trunk/blender/source/blender/editors/space_image/image_buttons.c 2013-03-12 13:03:58 UTC (rev 55213)
+++ trunk/blender/source/blender/editors/space_image/image_buttons.c 2013-03-12 13:18:39 UTC (rev 55214)
@@ -73,51 +73,54 @@
/* proto */
-static void image_info(Scene *scene, ImageUser *iuser, Image *ima, ImBuf *ibuf, char *str)
+static void image_info(Scene *scene, ImageUser *iuser, Image *ima, ImBuf *ibuf, char *str, size_t len)
{
- int ofs = 0;
+ size_t ofs = 0;
str[0] = 0;
-
- if (ima == NULL) return;
+ if (ima == NULL)
+ return;
if (ibuf == NULL) {
- ofs += sprintf(str, IFACE_("Can't Load Image"));
+ ofs += BLI_snprintf(str + ofs, len - ofs, "%s", IFACE_("Can't Load Image"));
}
else {
if (ima->source == IMA_SRC_MOVIE) {
- ofs += sprintf(str, IFACE_("Movie"));
+ ofs += BLI_snprintf(str + ofs, len - ofs, "%s", IFACE_("Movie"));
if (ima->anim)
- ofs += sprintf(str + ofs, IFACE_(" %d frs"), IMB_anim_get_duration(ima->anim, IMB_TC_RECORD_RUN));
+ ofs += BLI_snprintf(str + ofs, len - ofs, IFACE_(" %d frs"),
+ IMB_anim_get_duration(ima->anim, IMB_TC_RECORD_RUN));
}
else
- ofs += sprintf(str, IFACE_("Image"));
+ ofs += BLI_snprintf(str, len - ofs, "%s", IFACE_("Image"));
- ofs += sprintf(str + ofs, IFACE_(": size %d x %d,"), ibuf->x, ibuf->y);
+ ofs += BLI_snprintf(str + ofs, len - ofs, IFACE_(": size %d x %d,"), ibuf->x, ibuf->y);
if (ibuf->rect_float) {
if (ibuf->channels != 4) {
- ofs += sprintf(str + ofs, IFACE_("%d float channel(s)"), ibuf->channels);
+ ofs += BLI_snprintf(str + ofs, len - ofs, IFACE_("%d float channel(s)"), ibuf->channels);
}
else if (ibuf->planes == R_IMF_PLANES_RGBA)
- ofs += sprintf(str + ofs, IFACE_(" RGBA float"));
+ ofs += BLI_snprintf(str + ofs, len - ofs, "%s", IFACE_(" RGBA float"));
else
- ofs += sprintf(str + ofs, IFACE_(" RGB float"));
+ ofs += BLI_snprintf(str + ofs, len - ofs, "%s", IFACE_(" RGB float"));
}
else {
if (ibuf->planes == R_IMF_PLANES_RGBA)
- ofs += sprintf(str + ofs, IFACE_(" RGBA byte"));
+ ofs += BLI_snprintf(str + ofs, len - ofs, "%s", IFACE_(" RGBA byte"));
else
- ofs += sprintf(str + ofs, IFACE_(" RGB byte"));
+ ofs += BLI_snprintf(str + ofs, len - ofs, "%s", IFACE_(" RGB byte"));
}
if (ibuf->zbuf || ibuf->zbuf_float)
- ofs += sprintf(str + ofs, IFACE_(" + Z"));
+ ofs += BLI_snprintf(str + ofs, len - ofs, "%s", IFACE_(" + Z"));
if (ima->source == IMA_SRC_SEQUENCE) {
const char *file = BLI_last_slash(ibuf->name);
- if (file == NULL) file = ibuf->name;
- else file++;
- ofs += sprintf(str + ofs, ", %s", file);
+ if (file == NULL)
+ file = ibuf->name;
+ else
+ file++;
+ ofs += BLI_snprintf(str + ofs, len - ofs, ", %s", file);
}
}
@@ -125,10 +128,8 @@
if (ima->source == IMA_SRC_SEQUENCE) {
/* don't use iuser->framenr directly because it may not be updated if auto-refresh is off */
const int framenr = BKE_image_user_frame_get(iuser, CFRA, 0, NULL);
- ofs += sprintf(str + ofs, IFACE_(", Frame: %d"), framenr);
+ ofs += BLI_snprintf(str + ofs, len - ofs, IFACE_(", Frame: %d"), framenr);
}
-
- (void)ofs;
}
/* gets active viewer user */
@@ -539,6 +540,8 @@
void uiTemplateImage(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, PointerRNA *userptr, int compact)
{
+#define MAX_INFO_LEN 128
+
PropertyRNA *prop;
PointerRNA imaptr;
RNAUpdateCb *cb;
@@ -548,7 +551,7 @@
Scene *scene = CTX_data_scene(C);
uiLayout *row, *split, *col;
uiBlock *block;
- char str[128];
+ char str[MAX_INFO_LEN];
void *lock;
@@ -592,7 +595,7 @@
if (ima->source == IMA_SRC_VIEWER) {
ibuf = BKE_image_acquire_ibuf(ima, iuser, &lock);
- image_info(scene, iuser, ima, ibuf, str);
+ image_info(scene, iuser, ima, ibuf, str, MAX_INFO_LEN);
BKE_image_release_ibuf(ima, ibuf, lock);
uiItemL(layout, ima->id.name + 2, ICON_NONE);
@@ -662,7 +665,7 @@
else if (ima->source != IMA_SRC_GENERATED) {
if (compact == 0) {
ibuf = BKE_image_acquire_ibuf(ima, iuser, &lock);
- image_info(scene, iuser, ima, ibuf, str);
+ image_info(scene, iuser, ima, ibuf, str, MAX_INFO_LEN);
BKE_image_release_ibuf(ima, ibuf, lock);
uiItemL(layout, str, ICON_NONE);
}
@@ -750,6 +753,8 @@
}
MEM_freeN(cb);
+
+#undef MAX_INFO_LEN
}
void uiTemplateImageSettings(uiLayout *layout, PointerRNA *imfptr, int color_management)
Modified: trunk/blender/source/blender/editors/space_info/info_stats.c
===================================================================
--- trunk/blender/source/blender/editors/space_info/info_stats.c 2013-03-12 13:03:58 UTC (rev 55213)
+++ trunk/blender/source/blender/editors/space_info/info_stats.c 2013-03-12 13:18:39 UTC (rev 55214)
@@ -38,8 +38,9 @@
#include "DNA_meta_types.h"
#include "DNA_scene_types.h"
+#include "BLI_math.h"
+#include "BLI_string.h"
#include "BLI_utildefines.h"
-#include "BLI_math.h"
#include "BLF_translation.h"
@@ -58,6 +59,7 @@
#include "ED_armature.h"
#include "ED_mesh.h"
+#define MAX_INFO_LEN 512
typedef struct SceneStats {
int totvert, totvertsel;
@@ -68,7 +70,7 @@
int totlamp, totlampsel;
int tottri, totmesh;
- char infostr[512];
+ char infostr[MAX_INFO_LEN];
} SceneStats;
static void stats_object(Object *ob, int sel, int totob, SceneStats *stats)
@@ -357,60 +359,70 @@
static void stats_string(Scene *scene)
{
+#define MAX_INFO_MEM_LEN 64
SceneStats *stats = scene->stats;
Object *ob = (scene->basact) ? scene->basact->object : NULL;
uintptr_t mem_in_use, mmap_in_use;
- char memstr[64];
+ char memstr[MAX_INFO_MEM_LEN];
char *s;
+ size_t ofs = 0;
mem_in_use = MEM_get_memory_in_use();
mmap_in_use = MEM_get_mapped_memory_in_use();
/* get memory statistics */
- s = memstr + sprintf(memstr, IFACE_(" | Mem:%.2fM"), (double)((mem_in_use - mmap_in_use) >> 10) / 1024.0);
+ s = memstr;
+ ofs += BLI_snprintf(s + ofs, MAX_INFO_MEM_LEN - ofs, IFACE_(" | Mem:%.2fM"),
+ (double)((mem_in_use - mmap_in_use) >> 10) / 1024.0);
if (mmap_in_use)
- sprintf(s, IFACE_(" (%.2fM)"), (double)((mmap_in_use) >> 10) / 1024.0);
+ BLI_snprintf(s + ofs, MAX_INFO_MEM_LEN - ofs, IFACE_(" (%.2fM)"), (double)((mmap_in_use) >> 10) / 1024.0);
s = stats->infostr;
-
- s += sprintf(s, "%s | ", versionstr);
+ ofs = 0;
+ ofs += BLI_snprintf(s + ofs, MAX_INFO_LEN - ofs, "%s | ", versionstr);
+
if (scene->obedit) {
if (BKE_keyblock_from_object(scene->obedit))
- s += sprintf(s, IFACE_("(Key) "));
+ ofs += BLI_snprintf(s + ofs, MAX_INFO_LEN - ofs, "%s", IFACE_("(Key) "));
if (scene->obedit->type == OB_MESH) {
- s += sprintf(s, IFACE_("Verts:%d/%d | Edges:%d/%d | Faces:%d/%d | Tris:%d"),
- stats->totvertsel, stats->totvert, stats->totedgesel, stats->totedge, stats->totfacesel,
- stats->totface, stats->tottri);
+ ofs += BLI_snprintf(s + ofs, MAX_INFO_LEN - ofs,
+ IFACE_("Verts:%d/%d | Edges:%d/%d | Faces:%d/%d | Tris:%d"),
+ stats->totvertsel, stats->totvert, stats->totedgesel, stats->totedge,
+ stats->totfacesel, stats->totface, stats->tottri);
}
else if (scene->obedit->type == OB_ARMATURE) {
- s += sprintf(s, IFACE_("Verts:%d/%d | Bones:%d/%d"), stats->totvertsel, stats->totvert, stats->totbonesel,
- stats->totbone);
+ ofs += BLI_snprintf(s + ofs, MAX_INFO_LEN - ofs, IFACE_("Verts:%d/%d | Bones:%d/%d"), stats->totvertsel,
+ stats->totvert, stats->totbonesel, stats->totbone);
}
else {
- s += sprintf(s, IFACE_("Verts:%d/%d"), stats->totvertsel, stats->totvert);
+ ofs += BLI_snprintf(s + ofs, MAX_INFO_LEN - ofs, IFACE_("Verts:%d/%d"), stats->totvertsel, stats->totvert);
}
- strcat(s, memstr);
+ ofs += BLI_snprintf(s + ofs, MAX_INFO_LEN - ofs, "%s", memstr);
}
else if (ob && (ob->mode & OB_MODE_POSE)) {
- s += sprintf(s, IFACE_("Bones:%d/%d %s"),
- stats->totbonesel, stats->totbone, memstr);
+ ofs += BLI_snprintf(s + ofs, MAX_INFO_LEN - ofs, IFACE_("Bones:%d/%d %s"),
+ stats->totbonesel, stats->totbone, memstr);
}
else if (stats_is_object_dynamic_topology_sculpt(ob)) {
- s += sprintf(s, IFACE_("Verts:%d | Tris:%d"), stats->totvert, stats->tottri);
+ ofs += BLI_snprintf(s + ofs, MAX_INFO_LEN - ofs, IFACE_("Verts:%d | Tris:%d"), stats->totvert, stats->tottri);
}
else {
- s += sprintf(s, IFACE_("Verts:%d | Faces:%d | Tris:%d | Objects:%d/%d | Lamps:%d/%d%s"),
- stats->totvert, stats->totface, stats->tottri, stats->totobjsel, stats->totobj, stats->totlampsel,
- stats->totlamp, memstr);
+ ofs += BLI_snprintf(s + ofs, MAX_INFO_LEN - ofs,
+ IFACE_("Verts:%d | Faces:%d | Tris:%d | Objects:%d/%d | Lamps:%d/%d%s"), stats->totvert,
+ stats->totface, stats->tottri, stats->totobjsel, stats->totobj, stats->totlampsel,
+ stats->totlamp, memstr);
}
if (ob)
- sprintf(s, " | %s", ob->id.name + 2);
+ BLI_snprintf(s + ofs, MAX_INFO_LEN - ofs, " | %s", ob->id.name + 2);
+#undef MAX_INFO_MEM_LEN
}
+#undef MAX_INFO_LEN
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list