From: Nirbheek Chauhan Date: Mon, 27 Jul 2015 13:09:13 +0000 (+0530) Subject: opuscommon: Use GString instead of snprintf for concating X-Git-Tag: 1.10.4~478^2~22 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f04d4dd7c8bc4fe1f662ecbe0c7da6da224299be;p=platform%2Fupstream%2Fgst-plugins-base.git opuscommon: Use GString instead of snprintf for concating Safer, easier to understand, and more portable. Also, skip all this if the log level is too low. --- diff --git a/ext/opus/gstopuscommon.c b/ext/opus/gstopuscommon.c index 227d44a..febccd8 100644 --- a/ext/opus/gstopuscommon.c +++ b/ext/opus/gstopuscommon.c @@ -94,13 +94,18 @@ gst_opus_common_log_channel_mapping_table (GstElement * element, GstDebugCategory * category, const char *msg, int n_channels, const guint8 * table) { - char s[8 + 256 * 4] = "[ "; /* enough for 256 times "255 " at most */ int n; + GString *s; + if (gst_debug_category_get_threshold (category) < GST_LEVEL_INFO) + return; + + s = g_string_new ("[ "); for (n = 0; n < n_channels; ++n) { - size_t len = strlen (s); - snprintf (s + len, sizeof (s) - len, "%d ", table[n]); + g_string_append_printf (s, "%d ", table[n]); } - strcat (s, "]"); - GST_CAT_LEVEL_LOG (category, GST_LEVEL_INFO, element, "%s: %s", msg, s); + g_string_append (s, "]"); + + GST_CAT_LEVEL_LOG (category, GST_LEVEL_INFO, element, "%s: %s", msg, s->str); + g_string_free (s, TRUE); }