From 7c62f64682b54fc2eb753c6d393d2c366874ad47 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Mon, 7 Feb 2022 09:58:52 +0300 Subject: Eliminate stringop-overflow gcc-12 warning in CORD__next * cord/cordbscs.c (CORD__next): Reduce limit and i values by cur_pos; add cur_pos to i when fn() is called; add cur_pos to limit in cur_end assignment. --- cord/cordbscs.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'cord') diff --git a/cord/cordbscs.c b/cord/cordbscs.c index 5fd1e9cc..0f052a76 100644 --- a/cord/cordbscs.c +++ b/cord/cordbscs.c @@ -817,20 +817,20 @@ void CORD__next(CORD_pos p) if (cur_pos < end_pos) { /* Fill cache and return. */ size_t i; - size_t limit = cur_pos + FUNCTION_BUF_SZ; + size_t limit = FUNCTION_BUF_SZ; CORD_fn fn = f -> fn; void * client_data = f -> client_data; - if (limit > end_pos) { - limit = end_pos; + if (end_pos - cur_pos < FUNCTION_BUF_SZ) { + limit = end_pos - cur_pos; } - for (i = cur_pos; i < limit; i++) { - p[0].function_buf[i - cur_pos] = - (*fn)(i - start_pos, client_data); + for (i = 0; i < limit; i++) { + p[0].function_buf[i] = (*fn)(i + cur_pos - start_pos, + client_data); } p[0].cur_start = cur_pos; p[0].cur_leaf = p[0].function_buf; - p[0].cur_end = limit; + p[0].cur_end = cur_pos + limit; return; } } -- cgit v1.2.1