From cbc51ee1f71cb0007ac70adae48b05e26ab83f39 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Wed, 28 Sep 2016 10:27:12 +0300 Subject: [PATCH] Fix CORD_substr_closure for the case when CORD_from_fn returns C string * cord/cordbscs.c (CORD_substr_closure): Change type of "result" local variable from CORD to CordRep* (insert necessary type casts); update function.header only if function.null field is zero (i.e. CORD_from_fn returned pointer to CordRep, not a pointer to C character string). --- cord/cordbscs.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cord/cordbscs.c b/cord/cordbscs.c index d6c33ee..321ca94 100644 --- a/cord/cordbscs.c +++ b/cord/cordbscs.c @@ -352,15 +352,15 @@ char CORD_apply_access_fn(size_t i, void * client_data) CORD CORD_substr_closure(CORD x, size_t i, size_t n, CORD_fn f) { register struct substr_args * sa = GC_NEW(struct substr_args); - CORD result; + CordRep * result; if (sa == 0) OUT_OF_MEMORY; sa->sa_cord = (CordRep *)x; sa->sa_index = i; - result = CORD_from_fn(f, (void *)sa, n); - if (result == CORD_EMPTY) return CORD_EMPTY; /* n == 0 */ - ((CordRep *)result) -> function.header = SUBSTR_HDR; - return (result); + result = (CordRep *)CORD_from_fn(f, (void *)sa, n); + if ((CORD)result != CORD_EMPTY && 0 == result -> function.null) + result -> function.header = SUBSTR_HDR; + return (CORD)result; } # define SUBSTR_LIMIT (10 * SHORT_LIMIT) -- 2.7.4