From: Ivan Maidanski Date: Wed, 28 Sep 2016 07:27:12 +0000 (+0300) Subject: Fix CORD_substr_closure for the case when CORD_from_fn returns C string X-Git-Tag: v8.0.0~1135 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cbc51ee1f71cb0007ac70adae48b05e26ab83f39;p=gc 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). --- diff --git a/cord/cordbscs.c b/cord/cordbscs.c index d6c33ee9..321ca94d 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)