From: Ivan Maidanski Date: Wed, 2 Mar 2016 07:20:28 +0000 (+0300) Subject: Fix 'CORD_iter5 unused result' code defect in cordxtra X-Git-Tag: gc7_4_4~19 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=84912c531bd57fd366dd63eb2e7ec880d77d3747;p=gc 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). --- 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); }