Temp fix for stupid -Wformat-security issue.
[blender.git] / source / blender / editors / space_image / image_buttons.c
index 668d4a8..930d6c2 100644 (file)
 
 /* 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)