diff options
author | Edward Hervey <bilboed@bilboed.com> | 2015-02-25 08:26:19 +0100 |
---|---|---|
committer | Edward Hervey <bilboed@bilboed.com> | 2015-02-26 07:49:05 +0100 |
commit | 075def0f9771dd89503808e7d18f0569f7a76690 (patch) | |
tree | e1074cdd3dc5da6f7eb1530e29b1dbda23746748 | |
parent | 4245658d28ffb5e2e6fce2d21eab2d94ba1f0b86 (diff) |
gstvalue: Make sure GST_FOURCC_ARGS produces printable characters
Some systems will crash if we use non-printable characters in print/debug
statements.
Make sure that GST_FOURCC_ARGS never does that
https://bugzilla.gnome.org/show_bug.cgi?id=745144
-rw-r--r-- | gst/gstvalue.h | 12 | ||||
-rw-r--r-- | tests/check/gst/gstinfo.c | 18 |
2 files changed, 25 insertions, 5 deletions
diff --git a/gst/gstvalue.h b/gst/gstvalue.h index de01abc55..2e15642e9 100644 --- a/gst/gstvalue.h +++ b/gst/gstvalue.h @@ -80,12 +80,14 @@ G_BEGIN_DECLS * Can be used together with #GST_FOURCC_FORMAT to properly output a * #guint32 fourcc value in a printf()-style text message. */ -#define GST_FOURCC_ARGS(fourcc) \ - ((gchar) ((fourcc) &0xff)), \ - ((gchar) (((fourcc)>>8 )&0xff)), \ - ((gchar) (((fourcc)>>16)&0xff)), \ - ((gchar) (((fourcc)>>24)&0xff)) +#define __GST_PRINT_CHAR(c) \ + g_ascii_isprint(c) ? (c) : '.' +#define GST_FOURCC_ARGS(fourcc) \ + __GST_PRINT_CHAR((fourcc) & 0xff), \ + __GST_PRINT_CHAR(((fourcc) >> 8) & 0xff), \ + __GST_PRINT_CHAR(((fourcc) >> 16) & 0xff), \ + __GST_PRINT_CHAR(((fourcc) >> 24) & 0xff) /** * GST_VALUE_HOLDS_INT_RANGE: * @x: the #GValue to check diff --git a/tests/check/gst/gstinfo.c b/tests/check/gst/gstinfo.c index cd9b018a8..595b90845 100644 --- a/tests/check/gst/gstinfo.c +++ b/tests/check/gst/gstinfo.c @@ -332,6 +332,23 @@ GST_START_TEST (info_register_same_debug_category_twice) GST_END_TEST; #endif +GST_START_TEST (info_fourcc) +{ + gchar *res; + const gchar *cmp; + + cmp = "abcd"; + res = g_strdup_printf ("%" GST_FOURCC_FORMAT, GST_FOURCC_ARGS (0x64636261)); + fail_unless_equals_string (res, cmp); + g_free (res); + + cmp = ".bcd"; + res = g_strdup_printf ("%" GST_FOURCC_FORMAT, GST_FOURCC_ARGS (0x646362a9)); + fail_unless_equals_string (res, cmp); +} + +GST_END_TEST; + static Suite * gst_info_suite (void) { @@ -341,6 +358,7 @@ gst_info_suite (void) tcase_set_timeout (tc_chain, 30); suite_add_tcase (s, tc_chain); + tcase_add_test (tc_chain, info_fourcc); #ifndef GST_DISABLE_GST_DEBUG tcase_add_test (tc_chain, info_segment_format_printf_extension); tcase_add_test (tc_chain, info_ptr_format_printf_extension); |