From a83c67c1831708f760e7f421f6bd39242cf23176 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 11 Jan 2021 17:39:58 +1100 Subject: Fix incorrect use of BLI_snprintf in sequencer text concatenation The start of the text was stepped over without subtracting it's length (introduced in fad80a95fd08ec87a37f30f0b94a7061d4e382f2). Replace this logic with BLI_string_join_array to simplify construction. --- .../editors/space_sequencer/sequencer_draw.c | 43 +++++++++++++--------- 1 file changed, 25 insertions(+), 18 deletions(-) (limited to 'source/blender/editors/space_sequencer') diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index be9acf67ae8..9e6a21791d4 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -26,6 +26,7 @@ #include "BLI_blenlib.h" #include "BLI_math.h" +#include "BLI_string_utils.h" #include "BLI_threads.h" #include "BLI_utildefines.h" @@ -684,31 +685,37 @@ static size_t draw_seq_text_get_overlay_string(SpaceSeq *sseq, { const char *name = draw_seq_text_get_name(seq); char source[FILE_MAX]; - int strip_duration = seq->enddisp - seq->startdisp; draw_seq_text_get_source(seq, source, sizeof(source)); - bool show_name = sseq->flag & SEQ_SHOW_STRIP_NAME; - bool show_source = (sseq->flag & (SEQ_SHOW_STRIP_SOURCE)) && source[0] != '\0'; - bool show_duration = sseq->flag & SEQ_SHOW_STRIP_DURATION; + const char *text_sep = " | "; + const char *text_array[5]; + int i = 0; - size_t string_len = 0; - if (show_name) { - string_len = BLI_snprintf(r_overlay_string, overlay_string_len, "%s", name); - if (show_source || show_duration) { - string_len += BLI_snprintf(r_overlay_string + string_len, overlay_string_len, " | "); - } + if (sseq->flag & SEQ_SHOW_STRIP_NAME) { + text_array[i++] = name; } - if (show_source) { - string_len += BLI_snprintf(r_overlay_string + string_len, overlay_string_len, "%s", source); - if (show_duration) { - string_len += BLI_snprintf(r_overlay_string + string_len, overlay_string_len, " | "); + + if ((sseq->flag & SEQ_SHOW_STRIP_SOURCE) && (source[0] != '\0')) { + if (i != 0) { + text_array[i++] = text_sep; } + text_array[i++] = source; } - if (show_duration) { - string_len += BLI_snprintf( - r_overlay_string + string_len, overlay_string_len, "%d", strip_duration); + + char strip_duration_text[16]; + if (sseq->flag & SEQ_SHOW_STRIP_DURATION) { + const int strip_duration = seq->enddisp - seq->startdisp; + SNPRINTF(strip_duration_text, "%d", strip_duration); + if (i != 0) { + text_array[i++] = text_sep; + } + text_array[i++] = strip_duration_text; } - return string_len; + + BLI_assert(i <= ARRAY_SIZE(text_array)); + + return BLI_string_join_array(r_overlay_string, overlay_string_len, text_array, i) - + r_overlay_string; } /* Draw info text on a sequence strip. */ -- cgit v1.2.3