Fix incorrect BLI_snprintf usage

Event though in practice this wasn't causing problems as the fixed size
buffers are generally large enough not to truncate text.

Using the result from `snprint` or `BLI_snprintf` to step over a fixed
size buffer allows for buffer overruns as the returned value is the size
needed to copy the entire string, not the number of bytes copied.

Building strings using this convention with multiple calls:

    ofs += BLI_snprintf(str + ofs, str_len_max - ofs);

.. caused the size argument to become negative,
wrapping it to a large value when cast to the unsigned argument.
This commit is contained in:
2021-05-27 17:16:08 +10:00
parent 1276d0024f
commit 41f2ea4045
18 changed files with 204 additions and 199 deletions

View File

@@ -943,7 +943,7 @@ static int unit_scale_str(char *str,
/* Add the addition sign, the bias, and the close parenthesis after the value. */
int value_end_ofs = find_end_of_value_chars(str, len_max, prev_op_ofs + 2);
int len_bias_num = BLI_snprintf(str_tmp, TEMP_STR_SIZE, "+%.9g)", unit->bias);
int len_bias_num = BLI_snprintf_rlen(str_tmp, TEMP_STR_SIZE, "+%.9g)", unit->bias);
if (value_end_ofs + len_bias_num < len_max) {
memmove(str + value_end_ofs + len_bias_num, str + value_end_ofs, len - value_end_ofs + 1);
memcpy(str + value_end_ofs, str_tmp, len_bias_num);
@@ -957,7 +957,8 @@ static int unit_scale_str(char *str,
int len_move = (len - (found_ofs + len_name)) + 1; /* 1+ to copy the string terminator. */
/* "#" Removed later */
int len_num = BLI_snprintf(str_tmp, TEMP_STR_SIZE, "*%.9g" SEP_STR, unit->scalar / scale_pref);
int len_num = BLI_snprintf_rlen(
str_tmp, TEMP_STR_SIZE, "*%.9g" SEP_STR, unit->scalar / scale_pref);
if (len_num > len_max) {
len_num = len_max;

View File

@@ -216,10 +216,10 @@ size_t BLI_timecode_string_from_time_simple(char *str,
const int hun = ((int)(fmod(time_seconds, 1.0) * 100));
if (hr) {
rlen = BLI_snprintf(str, maxncpy, "%.2d:%.2d:%.2d.%.2d", hr, min, sec, hun);
rlen = BLI_snprintf_rlen(str, maxncpy, "%.2d:%.2d:%.2d.%.2d", hr, min, sec, hun);
}
else {
rlen = BLI_snprintf(str, maxncpy, "%.2d:%.2d.%.2d", min, sec, hun);
rlen = BLI_snprintf_rlen(str, maxncpy, "%.2d:%.2d.%.2d", min, sec, hun);
}
return rlen;

View File

@@ -190,7 +190,7 @@ static void motion_path_cache(OVERLAY_Data *vedata,
bool is_keyframe = (mpv->flag & MOTIONPATH_VERT_KEY) != 0;
if ((show_keyframes && show_keyframes_no && is_keyframe) || (show_frame_no && (i == 0))) {
numstr_len = BLI_snprintf(numstr, sizeof(numstr), " %d", frame);
numstr_len = BLI_snprintf_rlen(numstr, sizeof(numstr), " %d", frame);
DRW_text_cache_add(
dt, mpv->co, numstr, numstr_len, 0, 0, txt_flag, (is_keyframe) ? col_kf : col);
}
@@ -200,7 +200,7 @@ static void motion_path_cache(OVERLAY_Data *vedata,
/* Only draw frame number if several consecutive highlighted points
* don't occur on same point. */
if ((equals_v3v3(mpv->co, mpvP->co) == 0) || (equals_v3v3(mpv->co, mpvN->co) == 0)) {
numstr_len = BLI_snprintf(numstr, sizeof(numstr), " %d", frame);
numstr_len = BLI_snprintf_rlen(numstr, sizeof(numstr), " %d", frame);
DRW_text_cache_add(dt, mpv->co, numstr, numstr_len, 0, 0, txt_flag, col);
}
}

View File

@@ -2380,7 +2380,7 @@ static void float_array_to_string(float *values,
current_index++;
for (int i = 0; i < array_length; i++) {
int length = BLI_snprintf(
int length = BLI_snprintf_rlen(
output + current_index, output_len_max - current_index, "%f", values[i]);
current_index += length;

View File

@@ -1078,7 +1078,7 @@ static void template_ID(const bContext *C,
char numstr[32];
short numstr_len;
numstr_len = BLI_snprintf(numstr, sizeof(numstr), "%d", ID_REAL_USERS(id));
numstr_len = BLI_snprintf_rlen(numstr, sizeof(numstr), "%d", ID_REAL_USERS(id));
but = uiDefBut(
block,

View File

@@ -809,12 +809,12 @@ void uiTemplateMovieclipInformation(uiLayout *layout,
char str[1024];
size_t ofs = 0;
ofs += BLI_snprintf(str + ofs, sizeof(str) - ofs, TIP_("%d x %d"), width, height);
ofs += BLI_snprintf_rlen(str + ofs, sizeof(str) - ofs, TIP_("%d x %d"), width, height);
if (ibuf) {
if (ibuf->rect_float) {
if (ibuf->channels != 4) {
ofs += BLI_snprintf(
ofs += BLI_snprintf_rlen(
str + ofs, sizeof(str) - ofs, TIP_(", %d float channel(s)"), ibuf->channels);
}
else if (ibuf->planes == R_IMF_PLANES_RGBA) {
@@ -837,7 +837,7 @@ void uiTemplateMovieclipInformation(uiLayout *layout,
short frs_sec;
float frs_sec_base;
if (IMB_anim_get_fps(clip->anim, &frs_sec, &frs_sec_base, true)) {
ofs += BLI_snprintf(
ofs += BLI_snprintf_rlen(
str + ofs, sizeof(str) - ofs, TIP_(", %.2f fps"), (float)frs_sec / frs_sec_base);
}
}

View File

@@ -1218,11 +1218,12 @@ void uiTemplateImageInfo(uiLayout *layout, bContext *C, Image *ima, ImageUser *i
const int len = MAX_IMAGE_INFO_LEN;
int ofs = 0;
ofs += BLI_snprintf(str + ofs, len - ofs, TIP_("%d x %d, "), ibuf->x, ibuf->y);
ofs += BLI_snprintf_rlen(str + ofs, len - ofs, TIP_("%d x %d, "), ibuf->x, ibuf->y);
if (ibuf->rect_float) {
if (ibuf->channels != 4) {
ofs += BLI_snprintf(str + ofs, len - ofs, TIP_("%d float channel(s)"), ibuf->channels);
ofs += BLI_snprintf_rlen(
str + ofs, len - ofs, TIP_("%d float channel(s)"), ibuf->channels);
}
else if (ibuf->planes == R_IMF_PLANES_RGBA) {
ofs += BLI_strncpy_rlen(str + ofs, TIP_(" RGBA float"), len - ofs);

View File

@@ -505,14 +505,14 @@ static void get_stats_string(
LayerCollection *layer_collection = view_layer->active_collection;
if (object_mode == OB_MODE_OBJECT) {
*ofs += BLI_snprintf(info + *ofs,
len - *ofs,
"%s | ",
BKE_collection_ui_name_get(layer_collection->collection));
*ofs += BLI_snprintf_rlen(info + *ofs,
len - *ofs,
"%s | ",
BKE_collection_ui_name_get(layer_collection->collection));
}
if (ob) {
*ofs += BLI_snprintf(info + *ofs, len - *ofs, "%s | ", ob->id.name + 2);
*ofs += BLI_snprintf_rlen(info + *ofs, len - *ofs, "%s | ", ob->id.name + 2);
}
if (obedit) {
@@ -521,72 +521,72 @@ static void get_stats_string(
}
if (obedit->type == OB_MESH) {
*ofs += BLI_snprintf(info + *ofs,
len - *ofs,
TIP_("Verts:%s/%s | Edges:%s/%s | Faces:%s/%s | Tris:%s"),
stats_fmt->totvertsel,
stats_fmt->totvert,
stats_fmt->totedgesel,
stats_fmt->totedge,
stats_fmt->totfacesel,
stats_fmt->totface,
stats_fmt->tottri);
*ofs += BLI_snprintf_rlen(info + *ofs,
len - *ofs,
TIP_("Verts:%s/%s | Edges:%s/%s | Faces:%s/%s | Tris:%s"),
stats_fmt->totvertsel,
stats_fmt->totvert,
stats_fmt->totedgesel,
stats_fmt->totedge,
stats_fmt->totfacesel,
stats_fmt->totface,
stats_fmt->tottri);
}
else if (obedit->type == OB_ARMATURE) {
*ofs += BLI_snprintf(info + *ofs,
len - *ofs,
TIP_("Joints:%s/%s | Bones:%s/%s"),
stats_fmt->totvertsel,
stats_fmt->totvert,
stats_fmt->totbonesel,
stats_fmt->totbone);
*ofs += BLI_snprintf_rlen(info + *ofs,
len - *ofs,
TIP_("Joints:%s/%s | Bones:%s/%s"),
stats_fmt->totvertsel,
stats_fmt->totvert,
stats_fmt->totbonesel,
stats_fmt->totbone);
}
else {
*ofs += BLI_snprintf(
*ofs += BLI_snprintf_rlen(
info + *ofs, len - *ofs, TIP_("Verts:%s/%s"), stats_fmt->totvertsel, stats_fmt->totvert);
}
}
else if (ob && (object_mode & OB_MODE_POSE)) {
*ofs += BLI_snprintf(
*ofs += BLI_snprintf_rlen(
info + *ofs, len - *ofs, TIP_("Bones:%s/%s"), stats_fmt->totbonesel, stats_fmt->totbone);
}
else if ((ob) && (ob->type == OB_GPENCIL)) {
*ofs += BLI_snprintf(info + *ofs,
len - *ofs,
TIP_("Layers:%s | Frames:%s | Strokes:%s | Points:%s"),
stats_fmt->totgplayer,
stats_fmt->totgpframe,
stats_fmt->totgpstroke,
stats_fmt->totgppoint);
*ofs += BLI_snprintf_rlen(info + *ofs,
len - *ofs,
TIP_("Layers:%s | Frames:%s | Strokes:%s | Points:%s"),
stats_fmt->totgplayer,
stats_fmt->totgpframe,
stats_fmt->totgpstroke,
stats_fmt->totgppoint);
}
else if (ob && (object_mode & OB_MODE_SCULPT)) {
if (stats_is_object_dynamic_topology_sculpt(ob)) {
*ofs += BLI_snprintf(info + *ofs,
len - *ofs,
TIP_("Verts:%s | Tris:%s"),
stats_fmt->totvert,
stats_fmt->tottri);
*ofs += BLI_snprintf_rlen(info + *ofs,
len - *ofs,
TIP_("Verts:%s | Tris:%s"),
stats_fmt->totvert,
stats_fmt->tottri);
}
else {
*ofs += BLI_snprintf(info + *ofs,
len - *ofs,
TIP_("Verts:%s/%s | Faces:%s/%s"),
stats_fmt->totvertsculpt,
stats_fmt->totvert,
stats_fmt->totfacesculpt,
stats_fmt->totface);
*ofs += BLI_snprintf_rlen(info + *ofs,
len - *ofs,
TIP_("Verts:%s/%s | Faces:%s/%s"),
stats_fmt->totvertsculpt,
stats_fmt->totvert,
stats_fmt->totfacesculpt,
stats_fmt->totface);
}
}
else {
*ofs += BLI_snprintf(info + *ofs,
len - *ofs,
TIP_("Verts:%s | Faces:%s | Tris:%s"),
stats_fmt->totvert,
stats_fmt->totface,
stats_fmt->tottri);
*ofs += BLI_snprintf_rlen(info + *ofs,
len - *ofs,
TIP_("Verts:%s | Faces:%s | Tris:%s"),
stats_fmt->totvert,
stats_fmt->totface,
stats_fmt->tottri);
}
*ofs += BLI_snprintf(
*ofs += BLI_snprintf_rlen(
info + *ofs, len - *ofs, TIP_(" | Objects:%s/%s"), stats_fmt->totobjsel, stats_fmt->totobj);
}
@@ -613,11 +613,11 @@ static const char *info_statusbar_string(Main *bmain,
/* Memory status. */
if (statusbar_flag & STATUSBAR_SHOW_MEMORY) {
if (info[0]) {
ofs += BLI_snprintf(info + ofs, len - ofs, " | ");
ofs += BLI_snprintf_rlen(info + ofs, len - ofs, " | ");
}
uintptr_t mem_in_use = MEM_get_memory_in_use();
BLI_str_format_byte_unit(formatted_mem, mem_in_use, false);
ofs += BLI_snprintf(info + ofs, len, TIP_("Memory: %s"), formatted_mem);
ofs += BLI_snprintf_rlen(info + ofs, len, TIP_("Memory: %s"), formatted_mem);
}
/* GPU VRAM status. */
@@ -627,27 +627,27 @@ static const char *info_statusbar_string(Main *bmain,
float gpu_total_gb = gpu_tot_mem_kb / 1048576.0f;
float gpu_free_gb = gpu_free_mem_kb / 1048576.0f;
if (info[0]) {
ofs += BLI_snprintf(info + ofs, len - ofs, " | ");
ofs += BLI_snprintf_rlen(info + ofs, len - ofs, " | ");
}
if (gpu_free_mem_kb && gpu_tot_mem_kb) {
ofs += BLI_snprintf(info + ofs,
len - ofs,
TIP_("VRAM: %.1f/%.1f GiB"),
gpu_total_gb - gpu_free_gb,
gpu_total_gb);
ofs += BLI_snprintf_rlen(info + ofs,
len - ofs,
TIP_("VRAM: %.1f/%.1f GiB"),
gpu_total_gb - gpu_free_gb,
gpu_total_gb);
}
else {
/* Can only show amount of GPU VRAM available. */
ofs += BLI_snprintf(info + ofs, len - ofs, TIP_("VRAM: %.1f GiB Free"), gpu_free_gb);
ofs += BLI_snprintf_rlen(info + ofs, len - ofs, TIP_("VRAM: %.1f GiB Free"), gpu_free_gb);
}
}
/* Blender version. */
if (statusbar_flag & STATUSBAR_SHOW_VERSION) {
if (info[0]) {
ofs += BLI_snprintf(info + ofs, len - ofs, " | ");
ofs += BLI_snprintf_rlen(info + ofs, len - ofs, " | ");
}
ofs += BLI_snprintf(info + ofs, len - ofs, TIP_("%s"), BKE_blender_version_string());
ofs += BLI_snprintf_rlen(info + ofs, len - ofs, TIP_("%s"), BKE_blender_version_string());
}
return info;

View File

@@ -533,20 +533,21 @@ void headerRotation(TransInfo *t, char *str, const int str_size, float final)
outputNumInput(&(t->num), c, &t->scene->unit);
ofs += BLI_snprintf(
ofs += BLI_snprintf_rlen(
str + ofs, str_size - ofs, TIP_("Rotation: %s %s %s"), &c[0], t->con.text, t->proptext);
}
else {
ofs += BLI_snprintf(str + ofs,
str_size - ofs,
TIP_("Rotation: %.2f%s %s"),
RAD2DEGF(final),
t->con.text,
t->proptext);
ofs += BLI_snprintf_rlen(str + ofs,
str_size - ofs,
TIP_("Rotation: %.2f%s %s"),
RAD2DEGF(final),
t->con.text,
t->proptext);
}
if (t->flag & T_PROP_EDIT_ALL) {
ofs += BLI_snprintf(str + ofs, str_size - ofs, TIP_(" Proportional size: %.2f"), t->prop_size);
ofs += BLI_snprintf_rlen(
str + ofs, str_size - ofs, TIP_(" Proportional size: %.2f"), t->prop_size);
}
}
@@ -822,54 +823,55 @@ void headerResize(TransInfo *t, const float vec[3], char *str, const int str_siz
if (t->con.mode & CON_APPLY) {
switch (t->num.idx_max) {
case 0:
ofs += BLI_snprintf(
ofs += BLI_snprintf_rlen(
str + ofs, str_size - ofs, TIP_("Scale: %s%s %s"), &tvec[0], t->con.text, t->proptext);
break;
case 1:
ofs += BLI_snprintf(str + ofs,
str_size - ofs,
TIP_("Scale: %s : %s%s %s"),
&tvec[0],
&tvec[NUM_STR_REP_LEN],
t->con.text,
t->proptext);
ofs += BLI_snprintf_rlen(str + ofs,
str_size - ofs,
TIP_("Scale: %s : %s%s %s"),
&tvec[0],
&tvec[NUM_STR_REP_LEN],
t->con.text,
t->proptext);
break;
case 2:
ofs += BLI_snprintf(str + ofs,
str_size - ofs,
TIP_("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_rlen(str + ofs,
str_size - ofs,
TIP_("Scale: %s : %s : %s%s %s"),
&tvec[0],
&tvec[NUM_STR_REP_LEN],
&tvec[NUM_STR_REP_LEN * 2],
t->con.text,
t->proptext);
break;
}
}
else {
if (t->flag & T_2D_EDIT) {
ofs += BLI_snprintf(str + ofs,
str_size - ofs,
TIP_("Scale X: %s Y: %s%s %s"),
&tvec[0],
&tvec[NUM_STR_REP_LEN],
t->con.text,
t->proptext);
ofs += BLI_snprintf_rlen(str + ofs,
str_size - ofs,
TIP_("Scale X: %s Y: %s%s %s"),
&tvec[0],
&tvec[NUM_STR_REP_LEN],
t->con.text,
t->proptext);
}
else {
ofs += BLI_snprintf(str + ofs,
str_size - ofs,
TIP_("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_rlen(str + ofs,
str_size - ofs,
TIP_("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_ALL) {
ofs += BLI_snprintf(str + ofs, str_size - ofs, TIP_(" Proportional size: %.2f"), t->prop_size);
ofs += BLI_snprintf_rlen(
str + ofs, str_size - ofs, TIP_(" Proportional size: %.2f"), t->prop_size);
}
}

View File

@@ -72,7 +72,7 @@ static void headerSeqSlide(TransInfo *t, const float val[2], char str[UI_MAX_DRA
BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.0f, %.0f", val[0], val[1]);
}
ofs += BLI_snprintf(
ofs += BLI_snprintf_rlen(
str + ofs, UI_MAX_DRAW_STR - ofs, TIP_("Sequence Slide: %s%s, ("), &tvec[0], t->con.text);
const wmKeyMapItem *kmi = t->custom.mode.data;
@@ -80,10 +80,10 @@ static void headerSeqSlide(TransInfo *t, const float val[2], char str[UI_MAX_DRA
ofs += WM_keymap_item_to_string(kmi, false, str + ofs, UI_MAX_DRAW_STR - ofs);
}
ofs += BLI_snprintf(str + ofs,
UI_MAX_DRAW_STR - ofs,
TIP_(" or Alt) Expand to fit %s"),
WM_bool_as_string((t->flag & T_ALT_TRANSFORM) != 0));
ofs += BLI_snprintf_rlen(str + ofs,
UI_MAX_DRAW_STR - ofs,
TIP_(" or Alt) Expand to fit %s"),
WM_bool_as_string((t->flag & T_ALT_TRANSFORM) != 0));
}
static void applySeqSlideValue(TransInfo *t, const float val[2])

View File

@@ -1482,15 +1482,15 @@ static void applyEdgeSlide(TransInfo *t, const int UNUSED(mval[2]))
ofs += BLI_strncpy_rlen(str + ofs, &c[0], sizeof(str) - ofs);
}
else {
ofs += BLI_snprintf(str + ofs, sizeof(str) - ofs, "%.4f ", final);
ofs += BLI_snprintf_rlen(str + ofs, sizeof(str) - ofs, "%.4f ", final);
}
ofs += BLI_snprintf(
ofs += BLI_snprintf_rlen(
str + ofs, sizeof(str) - ofs, TIP_("(E)ven: %s, "), WM_bool_as_string(use_even));
if (use_even) {
ofs += BLI_snprintf(
ofs += BLI_snprintf_rlen(
str + ofs, sizeof(str) - ofs, TIP_("(F)lipped: %s, "), WM_bool_as_string(flipped));
}
ofs += BLI_snprintf(
ofs += BLI_snprintf_rlen(
str + ofs, sizeof(str) - ofs, TIP_("Alt or (C)lamp: %s"), WM_bool_as_string(is_clamp));
/* done with header string */

View File

@@ -79,7 +79,7 @@ static void applyShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
if (hasNumInput(&t->num)) {
char c[NUM_STR_REP_LEN];
outputNumInput(&(t->num), c, unit);
ofs += BLI_snprintf(str + ofs, sizeof(str) - ofs, "%s", c);
ofs += BLI_snprintf_rlen(str + ofs, sizeof(str) - ofs, "%s", c);
}
else {
/* default header print */
@@ -93,12 +93,12 @@ static void applyShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
true);
}
else {
ofs += BLI_snprintf(str + ofs, sizeof(str) - ofs, "%.4f", distance);
ofs += BLI_snprintf_rlen(str + ofs, sizeof(str) - ofs, "%.4f", distance);
}
}
if (t->proptext[0]) {
ofs += BLI_snprintf(str + ofs, sizeof(str) - ofs, " %s", t->proptext);
ofs += BLI_snprintf_rlen(str + ofs, sizeof(str) - ofs, " %s", t->proptext);
}
ofs += BLI_strncpy_rlen(str + ofs, ", (", sizeof(str) - ofs);

View File

@@ -76,10 +76,10 @@ static void headerTimeTranslate(TransInfo *t, char str[UI_MAX_DRAW_STR])
}
}
ofs += BLI_snprintf(str, UI_MAX_DRAW_STR, TIP_("DeltaX: %s"), &tvec[0]);
ofs += BLI_snprintf_rlen(str, UI_MAX_DRAW_STR, TIP_("DeltaX: %s"), &tvec[0]);
if (t->flag & T_PROP_EDIT_ALL) {
ofs += BLI_snprintf(
ofs += BLI_snprintf_rlen(
str + ofs, UI_MAX_DRAW_STR - ofs, TIP_(" Proportional size: %.2f"), t->prop_size);
}
}

View File

@@ -102,24 +102,24 @@ static void applyTrackball(TransInfo *t, const int UNUSED(mval[2]))
outputNumInput(&(t->num), c, &t->scene->unit);
ofs += BLI_snprintf(str + ofs,
sizeof(str) - ofs,
TIP_("Trackball: %s %s %s"),
&c[0],
&c[NUM_STR_REP_LEN],
t->proptext);
ofs += BLI_snprintf_rlen(str + ofs,
sizeof(str) - ofs,
TIP_("Trackball: %s %s %s"),
&c[0],
&c[NUM_STR_REP_LEN],
t->proptext);
}
else {
ofs += BLI_snprintf(str + ofs,
sizeof(str) - ofs,
TIP_("Trackball: %.2f %.2f %s"),
RAD2DEGF(phi[0]),
RAD2DEGF(phi[1]),
t->proptext);
ofs += BLI_snprintf_rlen(str + ofs,
sizeof(str) - ofs,
TIP_("Trackball: %.2f %.2f %s"),
RAD2DEGF(phi[0]),
RAD2DEGF(phi[1]),
t->proptext);
}
if (t->flag & T_PROP_EDIT_ALL) {
ofs += BLI_snprintf(
ofs += BLI_snprintf_rlen(
str + ofs, sizeof(str) - ofs, TIP_(" Proportional size: %.2f"), t->prop_size);
}

View File

@@ -141,67 +141,67 @@ static void headerTranslation(TransInfo *t, const float vec[3], char str[UI_MAX_
if (t->con.mode & CON_APPLY) {
switch (t->num.idx_max) {
case 0:
ofs += BLI_snprintf(str + ofs,
UI_MAX_DRAW_STR - ofs,
"D: %s (%s)%s %s %s",
&tvec[0],
distvec,
t->con.text,
t->proptext,
autoik);
ofs += BLI_snprintf_rlen(str + ofs,
UI_MAX_DRAW_STR - ofs,
"D: %s (%s)%s %s %s",
&tvec[0],
distvec,
t->con.text,
t->proptext,
autoik);
break;
case 1:
ofs += BLI_snprintf(str + ofs,
UI_MAX_DRAW_STR - ofs,
"D: %s D: %s (%s)%s %s %s",
&tvec[0],
&tvec[NUM_STR_REP_LEN],
distvec,
t->con.text,
t->proptext,
autoik);
ofs += BLI_snprintf_rlen(str + ofs,
UI_MAX_DRAW_STR - 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:
ofs += BLI_snprintf(str + ofs,
UI_MAX_DRAW_STR - 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);
ofs += BLI_snprintf_rlen(str + ofs,
UI_MAX_DRAW_STR - 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);
break;
}
}
else {
if (t->flag & T_2D_EDIT) {
ofs += BLI_snprintf(str + ofs,
UI_MAX_DRAW_STR - ofs,
"Dx: %s Dy: %s (%s)%s %s",
&tvec[0],
&tvec[NUM_STR_REP_LEN],
distvec,
t->con.text,
t->proptext);
ofs += BLI_snprintf_rlen(str + ofs,
UI_MAX_DRAW_STR - ofs,
"Dx: %s Dy: %s (%s)%s %s",
&tvec[0],
&tvec[NUM_STR_REP_LEN],
distvec,
t->con.text,
t->proptext);
}
else {
ofs += BLI_snprintf(str + ofs,
UI_MAX_DRAW_STR - 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);
ofs += BLI_snprintf_rlen(str + ofs,
UI_MAX_DRAW_STR - 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_ALL) {
ofs += BLI_snprintf(
ofs += BLI_snprintf_rlen(
str + ofs, UI_MAX_DRAW_STR - ofs, TIP_(" Proportional size: %.2f"), t->prop_size);
}
@@ -217,12 +217,12 @@ static void headerTranslation(TransInfo *t, const float vec[3], char str[UI_MAX_
WM_modalkeymap_items_to_string(
t->keymap, TFM_MODAL_INSERTOFS_TOGGLE_DIR, true, str_km, sizeof(str_km));
ofs += BLI_snprintf(str,
UI_MAX_DRAW_STR,
TIP_("Auto-offset set to %s - press %s to toggle direction | %s"),
str_dir,
str_km,
str_old);
ofs += BLI_snprintf_rlen(str,
UI_MAX_DRAW_STR,
TIP_("Auto-offset set to %s - press %s to toggle direction | %s"),
str_dir,
str_km,
str_old);
MEM_freeN((void *)str_old);
}

View File

@@ -606,15 +606,15 @@ static void applyVertSlide(TransInfo *t, const int UNUSED(mval[2]))
ofs += BLI_strncpy_rlen(str + ofs, &c[0], sizeof(str) - ofs);
}
else {
ofs += BLI_snprintf(str + ofs, sizeof(str) - ofs, "%.4f ", final);
ofs += BLI_snprintf_rlen(str + ofs, sizeof(str) - ofs, "%.4f ", final);
}
ofs += BLI_snprintf(
ofs += BLI_snprintf_rlen(
str + ofs, sizeof(str) - ofs, TIP_("(E)ven: %s, "), WM_bool_as_string(use_even));
if (use_even) {
ofs += BLI_snprintf(
ofs += BLI_snprintf_rlen(
str + ofs, sizeof(str) - ofs, TIP_("(F)lipped: %s, "), WM_bool_as_string(flipped));
}
ofs += BLI_snprintf(
ofs += BLI_snprintf_rlen(
str + ofs, sizeof(str) - ofs, TIP_("Alt or (C)lamp: %s"), WM_bool_as_string(is_clamp));
/* done with header string */

View File

@@ -516,7 +516,8 @@ static void write_jpeg(struct jpeg_compress_struct *cinfo, struct ImBuf *ibuf)
* The first "Blender" is a simple identify to help
* in the read process.
*/
text_len = BLI_snprintf(text, text_size, "Blender:%s:%s", prop->name, IDP_String(prop));
text_len = BLI_snprintf_rlen(
text, text_size, "Blender:%s:%s", prop->name, IDP_String(prop));
jpeg_write_marker(cinfo, JPEG_COM, (JOCTET *)text, text_len + 1);
/* TODO(sergey): Ideally we will try to re-use allocation as

View File

@@ -2253,7 +2253,7 @@ static PyObject *Matrix_str(MatrixObject *self)
for (col = 0; col < self->num_col; col++) {
maxsize[col] = 0;
for (row = 0; row < self->num_row; row++) {
const int size = BLI_snprintf(
const int size = BLI_snprintf_rlen(
dummy_buf, sizeof(dummy_buf), "%.4f", MATRIX_ITEM(self, row, col));
maxsize[col] = max_ii(maxsize[col], size);
}