From 6888fc5fc74936af74fd30042e45652951648ea4 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Wed, 9 Sep 2015 22:41:17 +0200 Subject: [PATCH] Get rid of the non-portable memmem The sequences we're after are found at the beginning or at the end of the buffer, there's no need to scan the whole thing. --- src/fe-text/gui-readline.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/fe-text/gui-readline.c b/src/fe-text/gui-readline.c index 91dec4ea..87c824cf 100644 --- a/src/fe-text/gui-readline.c +++ b/src/fe-text/gui-readline.c @@ -666,15 +666,11 @@ static void sig_input(void) /* use the bracketed paste mode to detect when the user pastes * some text into the entry */ if (paste_use_bracketed_mode != FALSE && paste_buffer->len > 12) { - /* try to find the start/end sequence */ - int seq_start = memmem(paste_buffer->data, - paste_buffer->len * g_array_get_element_size(paste_buffer), - bp_start, sizeof(bp_start)) != NULL, - seq_end = memmem(paste_buffer->data, - paste_buffer->len * g_array_get_element_size(paste_buffer), - bp_end, sizeof(bp_end)) != NULL; - - g_warning("found sequences : start %d end %d", seq_start, seq_end); + /* try to find the start/end sequence, we know that we + * either find those at the start/end of the buffer or + * we don't find those at all. */ + int seq_start = !memcmp(paste_buffer->data, bp_start, sizeof(bp_start)), + seq_end = !memcmp(paste_buffer->data + paste_buffer->len * g_array_get_element_size(paste_buffer) - sizeof(bp_end), bp_end, sizeof(bp_end)); if (seq_start) { paste_bracketed_mode = TRUE;