From f73687eba07b6bcde8c616d7026d321cd25534c7 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Wed, 2 Mar 2016 10:20:28 +0300 Subject: [PATCH] Fix 'CORD_iter5 unused result' code defect in cordxtra * cord/cordxtra.c (CORD_fill_buf): Return CORD_iter5() result (instead of void); update description comment. * cord/cordxtra.c (CORD_to_char_star): Do not execute CORD_fill_buf() if cord is empty (CORD_fill_buf returns 0 in case of empty cord); check CORD_fill_buf result (abort in case of unexpected result). --- cord/cordxtra.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cord/cordxtra.c b/cord/cordxtra.c index be336a5a..a185185c 100644 --- a/cord/cordxtra.c +++ b/cord/cordxtra.c @@ -136,15 +136,17 @@ int CORD_batched_fill_proc(const char * s, void * client_data) } /* Fill buf with len characters starting at i. */ -/* Assumes len characters are available. */ -void CORD_fill_buf(CORD x, size_t i, size_t len, char * buf) +/* Assumes len characters are available in buf. */ +/* Return 1 if buf is filled fully (and len is */ +/* non-zero), 0 otherwise. */ +int CORD_fill_buf(CORD x, size_t i, size_t len, char * buf) { CORD_fill_data fd; fd.len = len; fd.buf = buf; fd.count = 0; - (void)CORD_iter5(x, i, CORD_fill_proc, CORD_batched_fill_proc, &fd); + return CORD_iter5(x, i, CORD_fill_proc, CORD_batched_fill_proc, &fd); } int CORD_cmp(CORD x, CORD y) @@ -241,7 +243,8 @@ char * CORD_to_char_star(CORD x) char * result = GC_MALLOC_ATOMIC(len + 1); if (result == 0) OUT_OF_MEMORY; - CORD_fill_buf(x, 0, len, result); + if (len > 0 && CORD_fill_buf(x, 0, len, result) != 1) + ABORT("CORD_fill_buf malfunction"); result[len] = '\0'; return(result); } -- 2.40.0