From b028d914399effe8c6321c4597aa3e32928db532 Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Fri, 21 Jul 2017 11:04:17 -0400 Subject: [PATCH] tests:icles: Fix previous patch by implementing our memmem Using the string version of it will fail on '\0'. --- tests/icles/test-accurate-seek.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/tests/icles/test-accurate-seek.c b/tests/icles/test-accurate-seek.c index cb1675b72f..2be2dcc953 100644 --- a/tests/icles/test-accurate-seek.c +++ b/tests/icles/test-accurate-seek.c @@ -31,6 +31,29 @@ #define SAMPLE_FREQ 44100 +void * +_memmem (const void *haystack, size_t hlen, const void *needle, size_t nlen) +{ + int needle_first; + const void *p = haystack; + size_t plen = hlen; + + if (!nlen) + return NULL; + + needle_first = *(unsigned char *) needle; + + while (plen >= nlen && (p = memchr (p, needle_first, plen - nlen + 1))) { + if (!memcmp (p, needle, nlen)) + return (void *) p; + + p++; + plen = hlen - (p - haystack); + } + + return NULL; +} + static GstClockTime sample_to_nanotime (guint sample) { @@ -208,10 +231,7 @@ test_seek_FORMAT_TIME_by_sample (const gchar * fn, GList * seek_positions) buf = gst_sample_get_buffer (sample); gst_buffer_map (buf, &map, GST_MAP_READ); - if (map.size > answer_size) - found = NULL; - else - found = g_strstr_len (answer, answer_size, (gchar *) map.data); + found = _memmem (answer, answer_size, map.data, map.size); gst_buffer_unmap (buf, &map); g_assert (found != NULL);