Fix CORD_substr_closure for the case when CORD_from_fn returns C string
authorIvan Maidanski <ivmai@mail.ru>
Wed, 28 Sep 2016 07:27:12 +0000 (10:27 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Wed, 28 Sep 2016 07:27:12 +0000 (10:27 +0300)
* 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

index d6c33ee..321ca94 100644 (file)
@@ -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)