diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-03-14 14:39:18 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-03-14 14:39:18 +0400 |
commit | ffc8ecc5874931e7a0040141a7bc3ad1b70b17d0 (patch) | |
tree | e8c64602442e650b5c0c78a614d19a713571ecd0 /source/blender/editors | |
parent | cf3b3a1ba2159792fad7cc0c8ccb98a855534823 (diff) |
use BLI_strncpy_rlen() rather then BLI_snprintf() when no formatting is needed.
also replace sprintf with strcpy when no formatting is done.
Diffstat (limited to 'source/blender/editors')
10 files changed, 31 insertions, 31 deletions
diff --git a/source/blender/editors/armature/editarmature_retarget.c b/source/blender/editors/armature/editarmature_retarget.c index d002d82b868..536c5ff1f7c 100644 --- a/source/blender/editors/armature/editarmature_retarget.c +++ b/source/blender/editors/armature/editarmature_retarget.c @@ -409,11 +409,11 @@ static void renameTemplateBone(char *name, char *template_name, ListBase *editbo for (i = 0, j = 0; i < (MAXBONENAME - 1) && j < (MAXBONENAME - 1) && template_name[i] != '\0'; i++) { if (template_name[i] == '&') { if (template_name[i + 1] == 'S' || template_name[i + 1] == 's') { - j += sprintf(name + j, "%s", side_string); + j += BLI_strncpy_rlen(name + j, side_string, MAXBONENAME); i++; } else if (template_name[i + 1] == 'N' || template_name[i + 1] == 'n') { - j += sprintf(name + j, "%s", num_string); + j += BLI_strncpy_rlen(name + j, num_string, MAXBONENAME); i++; } else { diff --git a/source/blender/editors/armature/editarmature_sketch.c b/source/blender/editors/armature/editarmature_sketch.c index a84827bfe0f..a3515e0983d 100644 --- a/source/blender/editors/armature/editarmature_sketch.c +++ b/source/blender/editors/armature/editarmature_sketch.c @@ -170,16 +170,16 @@ const char *BIF_listTemplates(const bContext *UNUSED(C)) GHashIterator ghi; const char *menu_header = IFACE_("Template %t|None %x0|"); char *p; + const size_t template_size = (BLI_ghash_size(TEMPLATES_HASH) * 32 + 30); if (TEMPLATES_MENU != NULL) { MEM_freeN(TEMPLATES_MENU); } - TEMPLATES_MENU = MEM_callocN(sizeof(char) * (BLI_ghash_size(TEMPLATES_HASH) * 32 + 30), "skeleton template menu"); + TEMPLATES_MENU = MEM_callocN(sizeof(char) * template_size, "skeleton template menu"); p = TEMPLATES_MENU; - - p += sprintf(TEMPLATES_MENU, "%s", menu_header); + p += BLI_strncpy_rlen(p, menu_header, template_size); BLI_ghashIterator_init(&ghi, TEMPLATES_HASH); diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index ef882b2486b..5abbb7124c0 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -1037,7 +1037,7 @@ static void vgroup_duplicate(Object *ob) BLI_snprintf(name, sizeof(name), "%s_copy", dg->name); } else { - BLI_snprintf(name, sizeof(name), "%s", dg->name); + BLI_strncpy(name, dg->name, sizeof(name)); } cdg = defgroup_duplicate(dg); diff --git a/source/blender/editors/space_buttons/buttons_texture.c b/source/blender/editors/space_buttons/buttons_texture.c index 16d194d0929..1643921e4dd 100644 --- a/source/blender/editors/space_buttons/buttons_texture.c +++ b/source/blender/editors/space_buttons/buttons_texture.c @@ -404,7 +404,7 @@ void uiTemplateTextureUser(uiLayout *layout, bContext *C) } /* create button */ - BLI_snprintf(name, UI_MAX_NAME_STR, "%s", user->name); + BLI_strncpy(name, user->name, UI_MAX_NAME_STR); if (user->icon) { but = uiDefIconTextMenuBut(block, template_texture_user_menu, NULL, diff --git a/source/blender/editors/space_clip/clip_draw.c b/source/blender/editors/space_clip/clip_draw.c index 56f2998b047..58626c79363 100644 --- a/source/blender/editors/space_clip/clip_draw.c +++ b/source/blender/editors/space_clip/clip_draw.c @@ -944,7 +944,7 @@ static void draw_marker_texts(SpaceClip *sc, MovieTrackingTrack *track, MovieTra if (state[0]) BLI_snprintf(str, sizeof(str), "%s: %s", track->name, state); else - BLI_snprintf(str, sizeof(str), "%s", track->name); + BLI_strncpy(str, track->name, sizeof(str)); BLF_position(fontid, pos[0], pos[1], 0.0f); BLF_draw(fontid, str, sizeof(str)); diff --git a/source/blender/editors/space_image/image_buttons.c b/source/blender/editors/space_image/image_buttons.c index 930d6c271b4..fbabaaee32a 100644 --- a/source/blender/editors/space_image/image_buttons.c +++ b/source/blender/editors/space_image/image_buttons.c @@ -82,17 +82,18 @@ static void image_info(Scene *scene, ImageUser *iuser, Image *ima, ImBuf *ibuf, return; if (ibuf == NULL) { - ofs += BLI_snprintf(str + ofs, len - ofs, "%s", IFACE_("Can't Load Image")); + ofs += BLI_strncpy_rlen(str + ofs, IFACE_("Can't Load Image"), len - ofs); } else { if (ima->source == IMA_SRC_MOVIE) { - ofs += BLI_snprintf(str + ofs, len - ofs, "%s", IFACE_("Movie")); + ofs += BLI_strncpy_rlen(str + ofs, IFACE_("Movie"), len - ofs); if (ima->anim) ofs += BLI_snprintf(str + ofs, len - ofs, IFACE_(" %d frs"), IMB_anim_get_duration(ima->anim, IMB_TC_RECORD_RUN)); } - else - ofs += BLI_snprintf(str, len - ofs, "%s", IFACE_("Image")); + else { + ofs += BLI_strncpy_rlen(str, IFACE_("Image"), len - ofs); + } ofs += BLI_snprintf(str + ofs, len - ofs, IFACE_(": size %d x %d,"), ibuf->x, ibuf->y); @@ -101,18 +102,18 @@ static void image_info(Scene *scene, ImageUser *iuser, Image *ima, ImBuf *ibuf, ofs += BLI_snprintf(str + ofs, len - ofs, IFACE_("%d float channel(s)"), ibuf->channels); } else if (ibuf->planes == R_IMF_PLANES_RGBA) - ofs += BLI_snprintf(str + ofs, len - ofs, "%s", IFACE_(" RGBA float")); + ofs += BLI_strncpy_rlen(str + ofs, IFACE_(" RGBA float"), len - ofs); else - ofs += BLI_snprintf(str + ofs, len - ofs, "%s", IFACE_(" RGB float")); + ofs += BLI_strncpy_rlen(str + ofs, IFACE_(" RGB float"), len - ofs); } else { if (ibuf->planes == R_IMF_PLANES_RGBA) - ofs += BLI_snprintf(str + ofs, len - ofs, "%s", IFACE_(" RGBA byte")); + ofs += BLI_strncpy_rlen(str + ofs, IFACE_(" RGBA byte"), len - ofs); else - ofs += BLI_snprintf(str + ofs, len - ofs, "%s", IFACE_(" RGB byte")); + ofs += BLI_strncpy_rlen(str + ofs, IFACE_(" RGB byte"), len - ofs); } if (ibuf->zbuf || ibuf->zbuf_float) - ofs += BLI_snprintf(str + ofs, len - ofs, "%s", IFACE_(" + Z")); + ofs += BLI_strncpy_rlen(str + ofs, IFACE_(" + Z"), len - ofs); if (ima->source == IMA_SRC_SEQUENCE) { const char *file = BLI_last_slash(ibuf->name); diff --git a/source/blender/editors/space_info/info_stats.c b/source/blender/editors/space_info/info_stats.c index 141956b8919..b2e9427c799 100644 --- a/source/blender/editors/space_info/info_stats.c +++ b/source/blender/editors/space_info/info_stats.c @@ -384,7 +384,7 @@ static void stats_string(Scene *scene) if (scene->obedit) { if (BKE_keyblock_from_object(scene->obedit)) - ofs += BLI_snprintf(s + ofs, MAX_INFO_LEN - ofs, "%s", IFACE_("(Key) ")); + ofs += BLI_strncpy_rlen(s + ofs, IFACE_("(Key) "), MAX_INFO_LEN - ofs); if (scene->obedit->type == OB_MESH) { ofs += BLI_snprintf(s + ofs, MAX_INFO_LEN - ofs, @@ -400,7 +400,7 @@ static void stats_string(Scene *scene) ofs += BLI_snprintf(s + ofs, MAX_INFO_LEN - ofs, IFACE_("Verts:%d/%d"), stats->totvertsel, stats->totvert); } - ofs += BLI_snprintf(s + ofs, MAX_INFO_LEN - ofs, "%s", memstr); + ofs += BLI_strncpy_rlen(s + ofs, memstr, MAX_INFO_LEN - ofs); } else if (ob && (ob->mode & OB_MODE_POSE)) { ofs += BLI_snprintf(s + ofs, MAX_INFO_LEN - ofs, IFACE_("Bones:%d/%d %s"), diff --git a/source/blender/editors/space_nla/nla_draw.c b/source/blender/editors/space_nla/nla_draw.c index 242192218c8..56f2ec9ebe1 100644 --- a/source/blender/editors/space_nla/nla_draw.c +++ b/source/blender/editors/space_nla/nla_draw.c @@ -695,11 +695,8 @@ static void draw_nla_channel_list_gl(bAnimContext *ac, ListBase *anim_data, View special = ICON_ACTION; - if (act) - BLI_snprintf(name, sizeof(name), "%s", act->id.name + 2); - else - BLI_strncpy(name, "<No Action>", sizeof(name)); - + BLI_strncpy(name, act ? act->id.name + 2 : "<No Action>", sizeof(name)); + /* draw manually still */ do_draw = TRUE; } diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index cb6ca3f7a9a..64e49abd761 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -4112,7 +4112,7 @@ int ShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) applyNumInput(&t->num, &distance); /* header print for NumInput */ - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, "%s", IFACE_("Shrink/Fatten:")); + ofs += BLI_strncpy_rlen(str + ofs, IFACE_("Shrink/Fatten:"), MAX_INFO_LEN - ofs); if (hasNumInput(&t->num)) { char c[NUM_STR_REP_LEN]; outputNumInput(&(t->num), c); @@ -6481,12 +6481,12 @@ int VertSlide(TransInfo *t, const int UNUSED(mval[2])) } /* header string */ - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, "%s", IFACE_("Vert Slide: ")); + ofs += BLI_strncpy_rlen(str + ofs, IFACE_("Vert Slide: "), MAX_INFO_LEN - ofs); if (hasNumInput(&t->num)) { char c[NUM_STR_REP_LEN]; applyNumInput(&t->num, &final); outputNumInput(&(t->num), c); - ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, "%s", &c[0]); + ofs += BLI_strncpy_rlen(str + ofs, &c[0], MAX_INFO_LEN - ofs); } else { ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, "%.4f ", final); diff --git a/source/blender/editors/transform/transform_orientations.c b/source/blender/editors/transform/transform_orientations.c index 8f6563c9d6f..4fe36a15802 100644 --- a/source/blender/editors/transform/transform_orientations.c +++ b/source/blender/editors/transform/transform_orientations.c @@ -409,14 +409,16 @@ const char *BIF_menustringTransformOrientation(const bContext *C, const char *ti int i = V3D_MANIP_CUSTOM; char *str_menu, *p; const int elem_size = MAX_NAME + 4; + size_t str_menu_size; title = IFACE_(title); - str_menu = MEM_callocN(strlen(menu) + strlen(title) + 1 + elem_size * BIF_countTransformOrientation(C), "UserTransSpace from matrix"); + str_menu_size = strlen(menu) + strlen(title) + 1 + (elem_size * BIF_countTransformOrientation(C)); + str_menu = MEM_callocN(str_menu_size, "UserTransSpace from matrix"); + p = str_menu; - - p += sprintf(str_menu, "%s", title); - p += sprintf(p, "%s", menu); + p += BLI_strncpy_rlen(p, title, str_menu_size); + p += BLI_strncpy_rlen(p, menu, str_menu_size - (p - str_menu)); for (ts = transform_spaces->first; ts; ts = ts->next) { p += sprintf(p, "|%s %%x%d", ts->name, i++); |