[Bf-blender-cvs] [a83c67c1831] master: Fix incorrect use of BLI_snprintf in sequencer text concatenation

Campbell Barton noreply at git.blender.org
Mon Jan 11 07:53:26 CET 2021


Commit: a83c67c1831708f760e7f421f6bd39242cf23176
Author: Campbell Barton
Date:   Mon Jan 11 17:39:58 2021 +1100
Branches: master
https://developer.blender.org/rBa83c67c1831708f760e7f421f6bd39242cf23176

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.

===================================================================

M	source/blender/editors/space_sequencer/sequencer_draw.c

===================================================================

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. */



More information about the Bf-blender-cvs mailing list