diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2013-03-12 17:18:39 +0400 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2013-03-12 17:18:39 +0400 |
commit | b3ff0d6d2a95f461ae53c4e61b106b45c7aff48c (patch) | |
tree | 0073b1825a3c63cf1bc99187657fac34c1f8cce1 /source | |
parent | d74e0299543b862c17d73048bcfb2534291e6e9a (diff) |
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.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/intern/pointcache.c | 7 | ||||
-rw-r--r-- | source/blender/editors/space_image/image_buttons.c | 53 | ||||
-rw-r--r-- | source/blender/editors/space_info/info_stats.c | 56 | ||||
-rw-r--r-- | source/blender/editors/transform/transform.c | 360 |
4 files changed, 261 insertions, 215 deletions
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index c318356fd2a..c900d08e4e9 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -840,7 +840,10 @@ static int ptcache_dynamicpaint_read(PTCacheFile *pf, void *dp_v) /* 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 @@ static int ptcache_file_compressed_write(PTCacheFile *pf, unsigned char *in, uns 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; diff --git a/source/blender/editors/space_image/image_buttons.c b/source/blender/editors/space_image/image_buttons.c index 668d4a85bbd..930d6c271b4 100644 --- a/source/blender/editors/space_image/image_buttons.c +++ b/source/blender/editors/space_image/image_buttons.c @@ -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 @@ static void image_info(Scene *scene, ImageUser *iuser, Image *ima, ImBuf *ibuf, 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 @@ static void rna_update_cb(bContext *C, void *arg_cb, void *UNUSED(arg)) 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 @@ void uiTemplateImage(uiLayout *layout, bContext *C, PointerRNA *ptr, const char 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 @@ void uiTemplateImage(uiLayout *layout, bContext *C, PointerRNA *ptr, const char 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 @@ void uiTemplateImage(uiLayout *layout, bContext *C, PointerRNA *ptr, const char 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 @@ void uiTemplateImage(uiLayout *layout, bContext *C, PointerRNA *ptr, const char } MEM_freeN(cb); + +#undef MAX_INFO_LEN } void uiTemplateImageSettings(uiLayout *layout, PointerRNA *imfptr, int color_management) diff --git a/source/blender/editors/space_info/info_stats.c b/source/blender/editors/space_info/info_stats.c index 976769752f9..141956b8919 100644 --- a/source/blender/editors/space_info/info_stats.c +++ b/source/blender/editors/space_info/info_stats.c @@ -38,8 +38,9 @@ #include "DNA_meta_types.h" #include "DNA_scene_types.h" -#include "BLI_utildefines.h" #include "BLI_math.h" +#include "BLI_string.h" +#include "BLI_utildefines.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 @@ typedef struct SceneStats { 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_update(Scene *scene) 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 + void ED_info_stats_clear(Scene *scene) { if (scene->stats) { diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 924bd74b2bb..ca96afb5a5b 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -98,6 +98,8 @@ #include "transform.h" +#define MAX_INFO_LEN 256 + static void drawTransformApply(const struct bContext *C, ARegion *ar, void *arg); static int doEdgeSlide(TransInfo *t, float perc); static int doVertSlide(TransInfo *t, float perc); @@ -2658,7 +2660,8 @@ void initWarp(TransInfo *t) mid_v3_v3v3(t->center, min, max); - if (max[0] == min[0]) max[0] += 0.1f; /* not optimal, but flipping is better than invalid garbage (i.e. division by zero!) */ + if (max[0] == min[0]) + max[0] += 0.1f; /* not optimal, but flipping is better than invalid garbage (i.e. division by zero!) */ t->val = (max[0] - min[0]) / 2.0f; /* t->val is X dimension projected boundbox */ } @@ -2685,7 +2688,7 @@ int Warp(TransInfo *t, const int UNUSED(mval[2])) float vec[3], circumfac, dist, phi0, co, si, cursor[3], gcursor[3]; const float *curs; int i; - char str[50]; + char str[MAX_INFO_LEN]; curs = give_cursor(t->scene, t->view); /* @@ -2720,13 +2723,13 @@ int Warp(TransInfo *t, const int UNUSED(mval[2])) outputNumInput(&(t->num), c); - sprintf(str, IFACE_("Warp: %s"), c); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Warp: %s"), c); circumfac = DEG2RADF(circumfac); } else { /* default header print */ - sprintf(str, IFACE_("Warp: %.3f"), RAD2DEGF(circumfac)); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Warp: %.3f"), RAD2DEGF(circumfac)); } t->values[0] = circumfac; @@ -2844,7 +2847,7 @@ int Shear(TransInfo *t, const int UNUSED(mval[2])) float smat[3][3], tmat[3][3], totmat[3][3], persmat[3][3], persinv[3][3]; float value; int i; - char str[50]; + char str[MAX_INFO_LEN]; copy_m3_m4(persmat, t->viewmat); invert_m3_m3(persinv, persmat); @@ -2861,11 +2864,11 @@ int Shear(TransInfo *t, const int UNUSED(mval[2])) outputNumInput(&(t->num), c); - sprintf(str, IFACE_("Shear: %s %s"), c, t->proptext); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Shear: %s %s"), c, t->proptext); } else { /* default header print */ - sprintf(str, IFACE_("Shear: %.3f %s (Press X or Y to set shear axis)"), value, t->proptext); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Shear: %.3f %s (Press X or Y to set shear axis)"), value, t->proptext); } t->values[0] = value; @@ -2941,10 +2944,11 @@ void initResize(TransInfo *t) t->num.increment = t->snap[1]; } +/* We assume str is MAX_INFO_LEN long. */ static void headerResize(TransInfo *t, float vec[3], char *str) { char tvec[NUM_STR_REP_LEN * 3]; - char *spos = str; + size_t ofs = 0; if (hasNumInput(&t->num)) { outputNumInput(&(t->num), tvec); } @@ -2953,37 +2957,36 @@ static void headerResize(TransInfo *t, float vec[3], char *str) BLI_snprintf(&tvec[NUM_STR_REP_LEN], NUM_STR_REP_LEN, "%.4f", vec[1]); BLI_snprintf(&tvec[NUM_STR_REP_LEN * 2], NUM_STR_REP_LEN, "%.4f", vec[2]); } - + if (t->con.mode & CON_APPLY) { switch (t->num.idx_max) { case 0: - spos += sprintf(spos, IFACE_("Scale: %s%s %s"), &tvec[0], t->con.text, t->proptext); + ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("Scale: %s%s %s"), + &tvec[0], t->con.text, t->proptext); break; case 1: - spos += sprintf(spos, IFACE_("Scale: %s : %s%s %s"), &tvec[0], &tvec[NUM_STR_REP_LEN], - t->con.text, t->proptext); + ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("Scale: %s : %s%s %s"), + &tvec[0], &tvec[NUM_STR_REP_LEN], t->con.text, t->proptext); break; case 2: - spos += sprintf(spos, IFACE_("Scale: %s : %s : %s%s %s"), &tvec[0], &tvec[NUM_STR_REP_LEN], - &tvec[NUM_STR_REP_LEN * 2], t->con.text, t->proptext); + ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("Scale: %s : %s : %s%s %s"), &tvec[0], + &tvec[NUM_STR_REP_LEN], &tvec[NUM_STR_REP_LEN * 2], t->con.text, t->proptext); } } else { if (t->flag & T_2D_EDIT) { - spos += sprintf(spos, IFACE_("Scale X: %s Y: %s%s %s"), &tvec[0], &tvec[NUM_STR_REP_LEN], - t->con.text, t->proptext); + ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("Scale X: %s Y: %s%s %s"), + &tvec[0], &tvec[NUM_STR_REP_LEN], t->con.text, t->proptext); } else { - spos += sprintf(spos, IFACE_("Scale X: %s Y: %s Z: %s%s %s"), &tvec[0], &tvec[NUM_STR_REP_LEN], - &tvec[NUM_STR_REP_LEN * 2], t->con.text, t->proptext); + ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("Scale X: %s Y: %s Z: %s%s %s"), + &tvec[0], &tvec[NUM_STR_REP_LEN], &tvec[NUM_STR_REP_LEN * 2], t->con.text, t->proptext); } } - + if (t->flag & (T_PROP_EDIT | T_PROP_CONNECTED)) { - spos += sprintf(spos, IFACE_(" Proportional size: %.2f"), t->prop_size); + ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_(" Proportional size: %.2f"), t->prop_size); } - - (void)spos; } /* FLT_EPSILON is too small [#29633], 0.0000001f starts to flip */ @@ -3118,7 +3121,7 @@ int Resize(TransInfo *t, const int mval[2]) float size[3], mat[3][3]; float ratio; int i; - char str[200]; + char str[MAX_INFO_LEN]; /* for manipulator, center handle, the scaling can't be done relative to center */ if ((t->flag & T_USES_MANIPULATOR) && t->con.mode == 0) { @@ -3223,7 +3226,7 @@ int SkinResize(TransInfo *t, const int UNUSED(mval[2])) float size[3], mat[3][3]; float ratio; int i; - char str[200]; + char str[MAX_INFO_LEN]; ratio = t->values[0]; size[0] = size[1] = size[2] = ratio; @@ -3317,7 +3320,7 @@ int ToSphere(TransInfo *t, const int UNUSED(mval[2])) float vec[3]; float ratio, radius; int i; - char str[64]; + char str[MAX_INFO_LEN]; TransData *td = t->data; ratio = t->values[0]; @@ -3339,11 +3342,11 @@ int ToSphere(TransInfo *t, const int UNUSED(mval[2])) outputNumInput(&(t->num), c); - sprintf(str, IFACE_("To Sphere: %s %s"), c, t->proptext); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("To Sphere: %s %s"), c, t->proptext); } else { /* default header print */ - sprintf(str, IFACE_("To Sphere: %.4f %s"), ratio, t->proptext); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("To Sphere: %.4f %s"), ratio, t->proptext); } @@ -3532,7 +3535,8 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short quat_to_axis_angle(td->ext->rotAxis, td->ext->rotAngle, tquat); /* this function works on end result */ - protectedAxisAngleBits(td->protectflag, td->ext->rotAxis, td->ext->rotAngle, td->ext->irotAxis, td->ext->irotAngle); + protectedAxisAngleBits(td->protectflag, td->ext->rotAxis, td->ext->rotAngle, td->ext->irotAxis, + td->ext->irotAngle); } else { float eulmat[3][3]; @@ -3599,7 +3603,8 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short quat_to_axis_angle(td->ext->rotAxis, td->ext->rotAngle, tquat); /* this function works on end result */ - protectedAxisAngleBits(td->protectflag, td->ext->rotAxis, td->ext->rotAngle, td->ext->irotAxis, td->ext->irotAngle); + protectedAxisAngleBits(td->protectflag, td->ext->rotAxis, td->ext->rotAngle, td->ext->irotAxis, + td->ext->irotAngle); } else { float obmat[3][3]; @@ -3658,14 +3663,15 @@ static void applyRotation(TransInfo *t, float angle, float axis[3]) int Rotation(TransInfo *t, const int UNUSED(mval[2])) { - char str[128], *spos = str; - + char str[MAX_INFO_LEN]; + size_t ofs = 0; + float final; final = t->values[0]; - + snapGrid(t, &final); - + if ((t->con.mode & CON_APPLY) && t->con.applyRot) { t->con.applyRot(t, NULL, t->axis, NULL); } @@ -3673,9 +3679,9 @@ int Rotation(TransInfo *t, const int UNUSED(mval[2])) /* reset axis if constraint is not set */ copy_v3_v3(t->axis, t->axis_orig); } - + applySnapping(t, &final); - + if (hasNumInput(&t->num)) { char c[NUM_STR_REP_LEN]; @@ -3683,19 +3689,19 @@ int Rotation(TransInfo *t, const int UNUSED(mval[2])) outputNumInput(&(t->num), c); - spos += sprintf(spos, IFACE_("Rot: %s %s %s"), &c[0], t->con.text, t->proptext); + ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("Rot: %s %s %s"), &c[0], t->con.text, t->proptext); /* Clamp between -180 and 180 */ final = angle_wrap_rad(DEG2RADF(final)); } else { - spos += sprintf(spos, IFACE_("Rot: %.2f%s %s"), RAD2DEGF(final), t->con.text, t->proptext); + ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("Rot: %.2f%s %s"), + RAD2DEGF(final), t->con.text, t->proptext); } if (t->flag & (T_PROP_EDIT | T_PROP_CONNECTED)) { - spos += sprintf(spos, IFACE_(" Proportional size: %.2f"), t->prop_size); + ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_(" Proportional size: %.2f"), t->prop_size); } - (void)spos; t->values[0] = final; @@ -3760,7 +3766,8 @@ static void applyTrackball(TransInfo *t, float axis1[3], float axis2[3], float a int Trackball(TransInfo *t, const int UNUSED(mval[2])) { - char str[128], *spos = str; + char str[MAX_INFO_LEN]; + size_t ofs = 0; float axis1[3], axis2[3]; float mat[3][3], totmat[3][3], smat[3][3]; float phi[2]; @@ -3782,19 +3789,20 @@ int Trackball(TransInfo *t, const int UNUSED(mval[2])) outputNumInput(&(t->num), c); - spos += sprintf(spos, IFACE_("Trackball: %s %s %s"), &c[0], &c[NUM_STR_REP_LEN], t->proptext); + ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("Trackball: %s %s %s"), + &c[0], &c[NUM_STR_REP_LEN], t->proptext); phi[0] = DEG2RADF(phi[0]); phi[1] = DEG2RADF(phi[1]); } else { - spos += sprintf(spos, IFACE_("Trackball: %.2f %.2f %s"), RAD2DEGF(phi[0]), RAD2DEGF(phi[1]), t->proptext); + ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("Trackball: %.2f %.2f %s"), + RAD2DEGF(phi[0]), RAD2DEGF(phi[1]), t->proptext); } if (t->flag & (T_PROP_EDIT | T_PROP_CONNECTED)) { - spos += sprintf(spos, IFACE_(" Proportional size: %.2f"), t->prop_size); + ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_(" Proportional size: %.2f"), t->prop_size); } - (void)spos; vec_rot_to_mat3(smat, axis1, phi[0]); vec_rot_to_mat3(totmat, axis2, phi[1]); @@ -3858,9 +3866,10 @@ void initTranslation(TransInfo *t) t->num.increment = t->snap[1]; } +/* We assume str is MAX_INFO_LEN long. */ static void headerTranslation(TransInfo *t, float vec[3], char *str) { - char *spos = str; + size_t ofs = 0; char tvec[NUM_STR_REP_LEN * 3]; char distvec[NUM_STR_REP_LEN]; char autoik[NUM_STR_REP_LEN]; @@ -3881,29 +3890,30 @@ static void headerTranslation(TransInfo *t, float vec[3], char *str) int i, do_split = t->scene->unit.flag & USER_UNIT_OPT_SPLIT ? 1 : 0; for (i = 0; i < 3; i++) { - bUnit_AsString(&tvec[i * NUM_STR_REP_LEN], NUM_STR_REP_LEN, dvec[i] * t->scene->unit.scale_length, + bUnit_AsString(&tvec[NUM_STR_REP_LEN * i], NUM_STR_REP_LEN, dvec[i] * t->scene->unit.scale_length, 4, t->scene->unit.system, B_UNIT_LENGTH, do_split, 1); } } else { - sprintf(&tvec[0], "%.4f", dvec[0]); - sprintf(&tvec[NUM_STR_REP_LEN], "%.4f", dvec[1]); - sprintf(&tvec[NUM_STR_REP_LEN * 2], "%.4f", dvec[2]); + BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.4f", dvec[0]); + BLI_snprintf(&tvec[NUM_STR_REP_LEN], NUM_STR_REP_LEN, "%.4f", dvec[1]); + BLI_snprintf(&tvec[NUM_STR_REP_LEN * 2], NUM_STR_REP_LEN, "%.4f", dvec[2]); } } if (!(t->flag & T_2D_EDIT) && t->scene->unit.system) - bUnit_AsString(distvec, sizeof(distvec), dist * t->scene->unit.scale_length, 4, t->scene->unit.system, B_UNIT_LENGTH, t->scene->unit.flag & USER_UNIT_OPT_SPLIT, 0); + bUnit_AsString(distvec, sizeof(distvec), dist * t->scene->unit.scale_length, 4, t->scene->unit.system, + B_UNIT_LENGTH, t->scene->unit.flag & USER_UNIT_OPT_SPLIT, 0); else if (dist > 1e10f || dist < -1e10f) /* prevent string buffer overflow */ - sprintf(distvec, "%.4e", dist); + BLI_snprintf(distvec, NUM_STR_REP_LEN, "%.4e", dist); else - sprintf(distvec, "%.4f", dist); + BLI_snprintf(distvec, NUM_STR_REP_LEN, "%.4f", dist); if (t->flag & T_AUTOIK) { short chainlen = t->settings->autoik_chainlen; if (chainlen) - sprintf(autoik, IFACE_("AutoIK-Len: %d"), chainlen); + BLI_snprintf(autoik, NUM_STR_REP_LEN, IFACE_("AutoIK-Len: %d"), chainlen); else autoik[0] = '\0'; } @@ -3913,32 +3923,34 @@ static void headerTranslation(TransInfo *t, float vec[3], char *str) if (t->con.mode & CON_APPLY) { switch (t->num.idx_max) { case 0: - spos += sprintf(spos, "D: %s (%s)%s %s %s", &tvec[0], distvec, t->con.text, t->proptext, &autoik[0]); + ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, "D: %s (%s)%s %s %s", + &tvec[0], distvec, t->con.text, t->proptext, autoik); break; case 1: - spos += sprintf(spos, "D: %s D: %s (%s)%s %s %s", &tvec[0], &tvec[NUM_STR_REP_LEN], - distvec, t->con.text, t->proptext, &autoik[0]); + ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, "D: %s D: %s (%s)%s %s %s", + &tvec[0], &tvec[NUM_STR_REP_LEN], distvec, t->con.text, t->proptext, autoik); break; case 2: - spos += sprintf(spos, "D: %s D: %s D: %s (%s)%s %s %s", &tvec[0], &tvec[NUM_STR_REP_LEN], - &tvec[NUM_STR_REP_LEN * 2], distvec, t->con.text, t->proptext, &autoik[0]); + ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, "D: %s D: %s D: %s (%s)%s %s %s", + &tvec[0], &tvec[NUM_STR_REP_LEN], &tvec[NUM_STR_REP_LEN * 2], distvec, + t->con.text, t->proptext, autoik); } } else { if (t->flag & T_2D_EDIT) { - spos += sprintf(spos, "Dx: %s Dy: %s (%s)%s %s", &tvec[0], &tvec[NUM_STR_REP_LEN], - distvec, t->con.text, t->proptext); + ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, "Dx: %s Dy: %s (%s)%s %s", + &tvec[0], &tvec[NUM_STR_REP_LEN], distvec, t->con.text, t->proptext); } else { - spos += sprintf(spos, "Dx: %s Dy: %s Dz: %s (%s)%s %s %s", &tvec[0], &tvec[NUM_STR_REP_LEN], - &tvec[NUM_STR_REP_LEN * 2], distvec, t->con.text, t->proptext, &autoik[0]); + ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, "Dx: %s Dy: %s Dz: %s (%s)%s %s %s", + &tvec[0], &tvec[NUM_STR_REP_LEN], &tvec[NUM_STR_REP_LEN * 2], distvec, t->con.text, + t->proptext, autoik); } } - + if (t->flag & (T_PROP_EDIT | T_PROP_CONNECTED)) { - spos += sprintf(spos, IFACE_(" Proportional size: %.2f"), t->prop_size); + ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_(" Proportional size: %.2f"), t->prop_size); } - (void)spos; } static void applyTranslation(TransInfo *t, float vec[3]) @@ -4010,7 +4022,7 @@ static void applyTranslation(TransInfo *t, float vec[3]) /* uses t->vec to store actual translation in */ int Translation(TransInfo *t, const int UNUSED(mval[2])) { - char str[250]; + char str[MAX_INFO_LEN]; if (t->con.mode & CON_APPLY) { float pvec[3] = {0.0f, 0.0f, 0.0f}; @@ -4086,8 +4098,8 @@ int ShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) { float distance; int i; - char str[128]; - char *str_p; + char str[MAX_INFO_LEN]; + size_t ofs = 0; TransData *td = t->data; distance = -t->values[0]; @@ -4097,31 +4109,30 @@ int ShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) applyNumInput(&t->num, &distance); /* header print for NumInput */ - str_p = str; - str_p += BLI_snprintf(str_p, sizeof(str), IFACE_("Shrink/Fatten:")); + ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, "%s", IFACE_("Shrink/Fatten:")); if (hasNumInput(&t->num)) { char c[NUM_STR_REP_LEN]; outputNumInput(&(t->num), c); - str_p += BLI_snprintf(str_p, sizeof(str) - (str_p - str), " %s", c); + ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, " %s", c); } else { /* default header print */ - str_p += BLI_snprintf(str_p, sizeof(str) - (str_p - str), " %.4f", distance); + ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, " %.4f", distance); } if (t->proptext[0]) { - str_p += BLI_snprintf(str_p, sizeof(str) - (str_p - str), " %s", t->proptext); + ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, " %s", t->proptext); } - str_p += BLI_snprintf(str_p, sizeof(str) - (str_p - str), ", ("); + ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, ", ("); { wmKeyMapItem *kmi = WM_modalkeymap_find_propvalue(t->keymap, TFM_MODAL_RESIZE); if (kmi) { - str_p += WM_keymap_item_to_string(kmi, str_p, sizeof(str) - (str_p - str)); + ofs += WM_keymap_item_to_string(kmi, str + ofs, MAX_INFO_LEN - ofs); } } - str_p += BLI_snprintf(str_p, sizeof(str) - (str_p - str), IFACE_(" or Alt) Even Thickness %s"), - (t->flag & T_ALT_TRANSFORM) ? IFACE_("ON") : IFACE_("OFF")); + BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_(" or Alt) Even Thickness %s"), + (t->flag & T_ALT_TRANSFORM) ? IFACE_("ON") : IFACE_("OFF")); /* done with header string */ @@ -4177,7 +4188,7 @@ int Tilt(TransInfo *t, const int UNUSED(mval[2])) { TransData *td = t->data; int i; - char str[50]; + char str[MAX_INFO_LEN]; float final; @@ -4192,7 +4203,7 @@ int Tilt(TransInfo *t, const int UNUSED(mval[2])) outputNumInput(&(t->num), c); - sprintf(str, IFACE_("Tilt: %s° %s"), &c[0], t->proptext); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Tilt: %s° %s"), &c[0], t->proptext); final = DEG2RADF(final); @@ -4200,7 +4211,7 @@ int Tilt(TransInfo *t, const int UNUSED(mval[2])) t->values[0] = final; } else { - sprintf(str, IFACE_("Tilt: %.2f° %s"), RAD2DEGF(final), t->proptext); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Tilt: %.2f° %s"), RAD2DEGF(final), t->proptext); } for (i = 0; i < t->total; i++, td++) { @@ -4251,7 +4262,7 @@ int CurveShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) TransData *td = t->data; float ratio; int i; - char str[50]; + char str[MAX_INFO_LEN]; ratio = t->values[0]; @@ -4264,10 +4275,10 @@ int CurveShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) char c[NUM_STR_REP_LEN]; outputNumInput(&(t->num), c); - sprintf(str, IFACE_("Shrink/Fatten: %s"), c); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Shrink/Fatten: %s"), c); } else { - sprintf(str, IFACE_("Shrink/Fatten: %3f"), ratio); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Shrink/Fatten: %3f"), ratio); } for (i = 0; i < t->total; i++, td++) { @@ -4319,7 +4330,7 @@ int MaskShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) TransData *td; float ratio; int i, initial_feather = FALSE; - char str[50]; + char str[MAX_INFO_LEN]; ratio = t->values[0]; @@ -4332,10 +4343,10 @@ int MaskShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) char c[NUM_STR_REP_LEN]; outputNumInput(&(t->num), c); - sprintf(str, IFACE_("Feather Shrink/Fatten: %s"), c); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Feather Shrink/Fatten: %s"), c); } else { - sprintf(str, IFACE_("Feather Shrink/Fatten: %3f"), ratio); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Feather Shrink/Fatten: %3f"), ratio); } /* detect if no points have feather yet */ @@ -4405,7 +4416,7 @@ int PushPull(TransInfo *t, const int UNUSED(mval[2])) float vec[3], axis[3]; float distance; int i; - char str[128]; + char str[MAX_INFO_LEN]; TransData *td = t->data; distance = t->values[0]; @@ -4420,11 +4431,11 @@ int PushPull(TransInfo *t, const int UNUSED(mval[2])) outputNumInput(&(t->num), c); - sprintf(str, IFACE_("Push/Pull: %s%s %s"), c, t->con.text, t->proptext); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Push/Pull: %s%s %s"), c, t->con.text, t->proptext); } else { /* default header print */ - sprintf(str, IFACE_("Push/Pull: %.4f%s %s"), distance, t->con.text, t->proptext); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Push/Pull: %.4f%s %s"), distance, t->con.text, t->proptext); } t->values[0] = distance; @@ -4537,7 +4548,7 @@ int Bevel(TransInfo *t, const int UNUSED(mval[2])) { float distance, d; int i; - char str[128]; + char str[MAX_INFO_LEN]; const char *mode; TransData *td = t->data; @@ -4556,11 +4567,11 @@ int Bevel(TransInfo *t, const int UNUSED(mval[2])) outputNumInput(&(t->num), c); - sprintf(str, IFACE_("Bevel - Dist: %s, Mode: %s (MMB to toggle))"), c, mode); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Bevel - Dist: %s, Mode: %s (MMB to toggle))"), c, mode); } else { /* default header print */ - sprintf(str, IFACE_("Bevel - Dist: %.4f, Mode: %s (MMB to toggle))"), distance, mode); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Bevel - Dist: %.4f, Mode: %s (MMB to toggle))"), distance, mode); } if (distance < 0) distance = -distance; @@ -4606,7 +4617,7 @@ int BevelWeight(TransInfo *t, const int UNUSED(mval[2])) TransData *td = t->data; float weight; int i; - char str[50]; + char str[MAX_INFO_LEN]; weight = t->values[0]; @@ -4624,16 +4635,16 @@ int BevelWeight(TransInfo *t, const int UNUSED(mval[2])) outputNumInput(&(t->num), c); if (weight >= 0.0f) - sprintf(str, IFACE_("Bevel Weight: +%s %s"), c, t->proptext); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Bevel Weight: +%s %s"), c, t->proptext); else - sprintf(str, IFACE_("Bevel Weight: %s %s"), c, t->proptext); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Bevel Weight: %s %s"), c, t->proptext); } else { /* default header print */ if (weight >= 0.0f) - sprintf(str, IFACE_("Bevel Weight: +%.3f %s"), weight, t->proptext); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Bevel Weight: +%.3f %s"), weight, t->proptext); else - sprintf(str, IFACE_("Bevel Weight: %.3f %s"), weight, t->proptext); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Bevel Weight: %.3f %s"), weight, t->proptext); } for (i = 0; i < t->total; i++, td++) { @@ -4679,7 +4690,7 @@ int Crease(TransInfo *t, const int UNUSED(mval[2])) TransData *td = t->data; float crease; int i; - char str[50]; + char str[MAX_INFO_LEN]; crease = t->values[0]; @@ -4697,16 +4708,16 @@ int Crease(TransInfo *t, const int UNUSED(mval[2])) outputNumInput(&(t->num), c); if (crease >= 0.0f) - sprintf(str, IFACE_("Crease: +%s %s"), c, t->proptext); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Crease: +%s %s"), c, t->proptext); else - sprintf(str, IFACE_("Crease: %s %s"), c, t->proptext); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Crease: %s %s"), c, t->proptext); } else { /* default header print */ if (crease >= 0.0f) - sprintf(str, IFACE_("Crease: +%.3f %s"), crease, t->proptext); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Crease: +%.3f %s"), crease, t->proptext); else - sprintf(str, IFACE_("Crease: %.3f %s"), crease, t->proptext); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Crease: %.3f %s"), crease, t->proptext); } for (i = 0; i < t->total; i++, td++) { @@ -4750,6 +4761,7 @@ void initBoneSize(TransInfo *t) t->num.increment = t->snap[1]; } +/* We assume str is MAX_INFO_LEN long. */ static void headerBoneSize(TransInfo *t, float vec[3], char *str) { char tvec[NUM_STR_REP_LEN * 3]; @@ -4757,22 +4769,22 @@ static void headerBoneSize(TransInfo *t, float vec[3], char *str) outputNumInput(&(t->num), tvec); } else { - sprintf(&tvec[0], "%.4f", vec[0]); - sprintf(&tvec[NUM_STR_REP_LEN], "%.4f", vec[1]); - sprintf(&tvec[NUM_STR_REP_LEN * 2], "%.4f", vec[2]); + BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.4f", vec[0]); + BLI_snprintf(&tvec[NUM_STR_REP_LEN], NUM_STR_REP_LEN, "%.4f", vec[1]); + BLI_snprintf(&tvec[NUM_STR_REP_LEN * 2], NUM_STR_REP_LEN, "%.4f", vec[2]); } /* hmm... perhaps the y-axis values don't need to be shown? */ if (t->con.mode & CON_APPLY) { if (t->num.idx_max == 0) - sprintf(str, IFACE_("ScaleB: %s%s %s"), &tvec[0], t->con.text, t->proptext); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("ScaleB: %s%s %s"), &tvec[0], t->con.text, t->proptext); else - sprintf(str, IFACE_("ScaleB: %s : %s : %s%s %s"), &tvec[0], &tvec[NUM_STR_REP_LEN], - &tvec[NUM_STR_REP_LEN * 2], t->con.text, t->proptext); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("ScaleB: %s : %s : %s%s %s"), + &tvec[0], &tvec[NUM_STR_REP_LEN], &tvec[NUM_STR_REP_LEN * 2], t->con.text, t->proptext); } else { - sprintf(str, IFACE_("ScaleB X: %s Y: %s Z: %s%s %s"), &tvec[0], &tvec[NUM_STR_REP_LEN], - &tvec[NUM_STR_REP_LEN * 2], t->con.text, t->proptext); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("ScaleB X: %s Y: %s Z: %s%s %s"), + &tvec[0], &tvec[NUM_STR_REP_LEN], &tvec[NUM_STR_REP_LEN * 2], t->con.text, t->proptext); } } @@ -4802,7 +4814,7 @@ int BoneSize(TransInfo *t, const int mval[2]) float size[3], mat[3][3]; float ratio; int i; - char str[60]; + char str[MAX_INFO_LEN]; // TRANSFORM_FIX_ME MOVE TO MOUSE INPUT /* for manipulator, center handle, the scaling can't be done relative to center */ @@ -4875,7 +4887,7 @@ int BoneEnvelope(TransInfo *t, const int UNUSED(mval[2])) TransData *td = t->data; float ratio; int i; - char str[50]; + char str[MAX_INFO_LEN]; ratio = t->values[0]; @@ -4888,10 +4900,10 @@ int BoneEnvelope(TransInfo *t, const int UNUSED(mval[2])) char c[NUM_STR_REP_LEN]; outputNumInput(&(t->num), c); - sprintf(str, IFACE_("Envelope: %s"), c); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Envelope: %s"), c); } else { - sprintf(str, IFACE_("Envelope: %3f"), ratio); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Envelope: %3f"), ratio); } for (i = 0; i < t->total; i++, td++) { @@ -5608,7 +5620,8 @@ void projectEdgeSlideData(TransInfo *t, bool is_final) f_copy_flip = BLI_smallhash_lookup(&sld->origfaces, (uintptr_t)e_sel->l->f); } else if (BM_vert_in_face(e_sel->l->radial_next->f, sv->down)) { - f_copy_flip = BLI_smallhash_lookup(&sld->origfaces, (uintptr_t)e_sel->l->radial_next->f); + f_copy_flip = BLI_smallhash_lookup(&sld->origfaces, + (uintptr_t)e_sel->l->radial_next->f); } } @@ -5617,7 +5630,8 @@ void projectEdgeSlideData(TransInfo *t, bool is_final) f_copy_flip = BLI_smallhash_lookup(&sld->origfaces, (uintptr_t)e_sel->l->f); } else if (BM_vert_in_face(e_sel->l->radial_next->f, sv->up)) { - f_copy_flip = BLI_smallhash_lookup(&sld->origfaces, (uintptr_t)e_sel->l->radial_next->f); + f_copy_flip = BLI_smallhash_lookup(&sld->origfaces, + (uintptr_t)e_sel->l->radial_next->f); } } @@ -5933,12 +5947,15 @@ static int doEdgeSlide(TransInfo *t, float perc) int EdgeSlide(TransInfo *t, const int UNUSED(mval[2])) { - char str[128]; + char str[MAX_INFO_LEN]; float final; EdgeSlideData *sld = t->customData; bool flipped = sld->flipped_vtx; bool is_proportional = sld->is_proportional; + const char *on_str = IFACE_("ON"); + const char *off_str = IFACE_("OFF"); + final = t->values[0]; snapGrid(t, &final); @@ -5953,12 +5970,12 @@ int EdgeSlide(TransInfo *t, const int UNUSED(mval[2])) outputNumInput(&(t->num), c); - BLI_snprintf(str, sizeof(str), IFACE_("Edge Slide: %s (E)ven: %s, (F)lipped: %s"), - &c[0], !is_proportional ? IFACE_("ON") : IFACE_("OFF"), flipped ? IFACE_("ON") : IFACE_("OFF")); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Edge Slide: %s (E)ven: %s, (F)lipped: %s"), + &c[0], !is_proportional ? on_str : off_str, flipped ? on_str : off_str); } else { - BLI_snprintf(str, sizeof(str), IFACE_("Edge Slide: %.4f (E)ven: %s, (F)lipped: %s"), - final, !is_proportional ? IFACE_("ON") : IFACE_("OFF"), flipped ? IFACE_("ON") : IFACE_("OFF")); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Edge Slide: %.4f (E)ven: %s, (F)lipped: %s"), + final, !is_proportional ? on_str : off_str, flipped ? on_str : off_str); } CLAMP(final, -1.0f, 1.0f); @@ -5966,10 +5983,11 @@ int EdgeSlide(TransInfo *t, const int UNUSED(mval[2])) t->values[0] = final; /*do stuff here*/ - if (t->customData) + if (t->customData) { doEdgeSlide(t, final); + } else { - strcpy(str, IFACE_("Invalid Edge Selection")); + BLI_strncpy(str, IFACE_("Invalid Edge Selection"), MAX_INFO_LEN); t->state = TRANS_CANCEL; } @@ -6438,8 +6456,8 @@ static int doVertSlide(TransInfo *t, float perc) int VertSlide(TransInfo *t, const int UNUSED(mval[2])) { - char str[128]; - char *str_p; + char str[MAX_INFO_LEN]; + size_t ofs = 0; float final; VertSlideData *sld = t->customData; const bool flipped = sld->flipped_vtx; @@ -6447,6 +6465,9 @@ int VertSlide(TransInfo *t, const int UNUSED(mval[2])) const bool is_clamp = !(t->flag & T_ALT_TRANSFORM); const bool is_constrained = !(is_clamp == false || hasNumInput(&t->num)); + const char *on_str = IFACE_("ON"); + const char *off_str = IFACE_("OFF"); + final = t->values[0]; snapGrid(t, &final); @@ -6457,25 +6478,21 @@ int VertSlide(TransInfo *t, const int UNUSED(mval[2])) } /* header string */ - str_p = str; - str_p += BLI_snprintf(str_p, sizeof(str), IFACE_("Vert Slide: ")); + ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, "%s", IFACE_("Vert Slide: ")); if (hasNumInput(&t->num)) { char c[NUM_STR_REP_LEN]; applyNumInput(&t->num, &final); outputNumInput(&(t->num), c); - str_p += BLI_snprintf(str_p, sizeof(str) - (str_p - str), "%s", &c[0]); + ofs += BLI_snprintf(str, MAX_INFO_LEN - ofs, "%s", &c[0]); } else { - str_p += BLI_snprintf(str_p, sizeof(str) - (str_p - str), "%.4f ", final); + ofs += BLI_snprintf(str, MAX_INFO_LEN - ofs, "%.4f ", final); } - str_p += BLI_snprintf(str_p, sizeof(str) - (str_p - str), IFACE_("(E)ven: %s, "), - !is_proportional ? IFACE_("ON") : IFACE_("OFF")); + ofs += BLI_snprintf(str, MAX_INFO_LEN - ofs, IFACE_("(E)ven: %s, "), !is_proportional ? on_str : off_str); if (!is_proportional) { - str_p += BLI_snprintf(str_p, sizeof(str) - (str_p - str), IFACE_("(F)lipped: %s, "), - flipped ? IFACE_("ON") : IFACE_("OFF")); + ofs += BLI_snprintf(str, MAX_INFO_LEN - ofs, IFACE_("(F)lipped: %s, "), flipped ? on_str : off_str); } - str_p += BLI_snprintf(str_p, sizeof(str) - (str_p - str), IFACE_("Alt or (C)lamp: %s"), - is_clamp ? IFACE_("ON") : IFACE_("OFF")); + ofs += BLI_snprintf(str, MAX_INFO_LEN - ofs, IFACE_("Alt or (C)lamp: %s"), is_clamp ? on_str : off_str); /* done with header string */ /*do stuff here*/ @@ -6483,7 +6500,7 @@ int VertSlide(TransInfo *t, const int UNUSED(mval[2])) doVertSlide(t, final); } else { - strcpy(str, IFACE_("Invalid Vert Selection")); + BLI_strncpy(str, IFACE_("Invalid Vert Selection"), MAX_INFO_LEN); t->state = TRANS_CANCEL; } @@ -6519,7 +6536,7 @@ int BoneRoll(TransInfo *t, const int UNUSED(mval[2])) { TransData *td = t->data; int i; - char str[50]; + char str[MAX_INFO_LEN]; float final; @@ -6534,12 +6551,12 @@ int BoneRoll(TransInfo *t, const int UNUSED(mval[2])) outputNumInput(&(t->num), c); - sprintf(str, IFACE_("Roll: %s"), &c[0]); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Roll: %s"), &c[0]); final = DEG2RADF(final); } else { - sprintf(str, IFACE_("Roll: %.2f"), RAD2DEGF(final)); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Roll: %.2f"), RAD2DEGF(final)); } /* set roll values */ @@ -6581,7 +6598,7 @@ int BakeTime(TransInfo *t, const int mval[2]) TransData *td = t->data; float time; int i; - char str[50]; + char str[MAX_INFO_LEN]; float fac = 0.1f; @@ -6605,16 +6622,16 @@ int BakeTime(TransInfo *t, const int mval[2]) outputNumInput(&(t->num), c); if (time >= 0.0f) - sprintf(str, IFACE_("Time: +%s %s"), c, t->proptext); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Time: +%s %s"), c, t->proptext); else - sprintf(str, IFACE_("Time: %s %s"), c, t->proptext); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Time: %s %s"), c, t->proptext); } else { /* default header print */ if (time >= 0.0f) - sprintf(str, IFACE_("Time: +%.3f %s"), time, t->proptext); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Time: +%.3f %s"), time, t->proptext); else - sprintf(str, IFACE_("Time: %.3f %s"), time, t->proptext); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Time: %.3f %s"), time, t->proptext); } for (i = 0; i < t->total; i++, td++) { @@ -6656,7 +6673,7 @@ int Mirror(TransInfo *t, const int UNUSED(mval[2])) TransData *td; float size[3], mat[3][3]; int i; - char str[200]; + char str[MAX_INFO_LEN]; /* * OPTIMIZATION: @@ -6674,7 +6691,7 @@ int Mirror(TransInfo *t, const int UNUSED(mval[2])) t->con.applySize(t, NULL, mat); } - sprintf(str, IFACE_("Mirror%s"), t->con.text); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Mirror%s"), t->con.text); for (i = 0, td = t->data; i < t->total; i++, td++) { if (td->flag & TD_NOACTION) @@ -6791,29 +6808,29 @@ void initSeqSlide(TransInfo *t) t->num.increment = t->snap[1]; } -static void headerSeqSlide(TransInfo *t, float val[2], char *str, size_t str_len) +/* We assume str is MAX_INFO_LEN long. */ +static void headerSeqSlide(TransInfo *t, float val[2], char *str) { char tvec[NUM_STR_REP_LEN * 3]; - char *str_p; + size_t ofs = 0; if (hasNumInput(&t->num)) { outputNumInput(&(t->num), tvec); } else { - sprintf(&tvec[0], "%.0f, %.0f", val[0], val[1]); + BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.0f, %.0f", val[0], val[1]); } - str_p = str; - str_p += BLI_snprintf(str, str_len, IFACE_("Sequence Slide: %s%s, ("), &tvec[0], t->con.text); + ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("Sequence Slide: %s%s, ("), &tvec[0], t->con.text); { wmKeyMapItem *kmi = WM_modalkeymap_find_propvalue(t->keymap, TFM_MODAL_TRANSLATE); if (kmi) { - str_p += WM_keymap_item_to_string(kmi, str_p, str_len - (str_p - str)); + ofs += WM_keymap_item_to_string(kmi, str + ofs, MAX_INFO_LEN - ofs); } } - str_p += BLI_snprintf(str_p, str_len - (str_p - str), IFACE_(" or Alt) Expand to fit %s"), - (t->flag & T_ALT_TRANSFORM) ? IFACE_("ON") : IFACE_("OFF")); + ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_(" or Alt) Expand to fit %s"), + (t->flag & T_ALT_TRANSFORM) ? IFACE_("ON") : IFACE_("OFF")); } static void applySeqSlide(TransInfo *t, float val[2]) @@ -6841,7 +6858,7 @@ static void applySeqSlide(TransInfo *t, float val[2]) int SeqSlide(TransInfo *t, const int UNUSED(mval[2])) { - char str[200]; + char str[MAX_INFO_LEN]; if (t->con.mode & CON_APPLY) { float pvec[3] = {0.0f, 0.0f, 0.0f}; @@ -6857,7 +6874,7 @@ int SeqSlide(TransInfo *t, const int UNUSED(mval[2])) t->values[0] = floor(t->values[0] + 0.5f); t->values[1] = floor(t->values[1] + 0.5f); - headerSeqSlide(t, t->values, str, sizeof(str)); + headerSeqSlide(t, t->values, str); applySeqSlide(t, t->values); recalcData(t); @@ -6957,7 +6974,11 @@ static void doAnimEdit_SnapFrame(TransInfo *t, TransData *td, TransData2D *td2d, #if 0 /* 'do_time' disabled for now */ const Scene *scene = t->scene; - const short do_time = 0; //getAnimEdit_DrawTime(t); // NOTE: this works, but may be confusing behavior given the option's label, hence disabled +#if 0 /* NOTE: this works, but may be confusing behavior given the option's label, hence disabled */ + const short do_time = getAnimEdit_DrawTime(t); +#else + const short do_time = 0; +#endif const double secf = FPS; #endif double val; @@ -7045,6 +7066,7 @@ void initTimeTranslate(TransInfo *t) t->num.increment = t->snap[1]; } +/* We assume str is MAX_INFO_LEN long. */ static void headerTimeTranslate(TransInfo *t, char *str) { char tvec[NUM_STR_REP_LEN * 3]; @@ -7073,12 +7095,12 @@ static void headerTimeTranslate(TransInfo *t, char *str) } if (autosnap == SACTSNAP_FRAME) - sprintf(&tvec[0], "%d.00 (%.4f)", (int)val, val); + BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%d.00 (%.4f)", (int)val, val); else - sprintf(&tvec[0], "%.4f", val); + BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.4f", val); } - sprintf(str, IFACE_("DeltaX: %s"), &tvec[0]); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("DeltaX: %s"), &tvec[0]); } static void applyTimeTranslate(TransInfo *t, float UNUSED(sval)) @@ -7142,7 +7164,7 @@ int TimeTranslate(TransInfo *t, const int mval[2]) { View2D *v2d = (View2D *)t->view; float cval[2], sval[2]; - char str[200]; + char str[MAX_INFO_LEN]; /* calculate translation amount from mouse movement - in 'time-grid space' */ UI_view2d_region_to_view(v2d, mval[0], mval[0], &cval[0], &cval[1]); @@ -7200,6 +7222,7 @@ void initTimeSlide(TransInfo *t) t->num.increment = t->snap[1]; } +/* We assume str is MAX_INFO_LEN long. */ static void headerTimeSlide(TransInfo *t, float sval, char *str) { char tvec[NUM_STR_REP_LEN * 3]; @@ -7216,10 +7239,10 @@ static void headerTimeSlide(TransInfo *t, float sval, char *str) val = 2.0f * (cval - sval) / (maxx - minx); CLAMP(val, -1.0f, 1.0f); - sprintf(&tvec[0], "%.4f", val); + BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.4f", val); } - sprintf(str, IFACE_("TimeSlide: %s"), &tvec[0]); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("TimeSlide: %s"), &tvec[0]); } static void applyTimeSlide(TransInfo *t, float sval) @@ -7275,7 +7298,7 @@ int TimeSlide(TransInfo *t, const int mval[2]) float cval[2], sval[2]; float minx = *((float *)(t->customData)); float maxx = *((float *)(t->customData) + 1); - char str[200]; + char str[MAX_INFO_LEN]; /* calculate mouse co-ordinates */ UI_view2d_region_to_view(v2d, mval[0], mval[1], &cval[0], &cval[1]); @@ -7342,6 +7365,7 @@ void initTimeScale(TransInfo *t) t->num.increment = t->snap[1]; } +/* We assume str is MAX_INFO_LEN long. */ static void headerTimeScale(TransInfo *t, char *str) { char tvec[NUM_STR_REP_LEN * 3]; @@ -7349,9 +7373,9 @@ static void headerTimeScale(TransInfo *t, char *str) if (hasNumInput(&t->num)) outputNumInput(&(t->num), tvec); else - sprintf(&tvec[0], "%.4f", t->values[0]); + BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.4f", t->values[0]); - sprintf(str, IFACE_("ScaleX: %s"), &tvec[0]); + BLI_snprintf(str, MAX_INFO_LEN, IFACE_("ScaleX: %s"), &tvec[0]); } static void applyTimeScale(TransInfo *t) @@ -7396,7 +7420,7 @@ static void applyTimeScale(TransInfo *t) int TimeScale(TransInfo *t, const int UNUSED(mval[2])) { - char str[200]; + char str[MAX_INFO_LEN]; /* handle numeric-input stuff */ t->vec[0] = t->values[0]; @@ -7427,3 +7451,5 @@ bool checkUseLocalCenter_GraphEdit(TransInfo *t) { return ((t->around == V3D_LOCAL) && !ELEM3(t->mode, TFM_TRANSLATION, TFM_TIME_TRANSLATE, TFM_TIME_SLIDE)); } + +#undef MAX_INFO_LEN
\ No newline at end of file |