Eliminate 'write to memory that was const-qualified' code analyzer warning
authorIvan Maidanski <ivmai@mail.ru>
Wed, 28 Sep 2016 08:32:55 +0000 (11:32 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Wed, 28 Sep 2016 08:32:55 +0000 (11:32 +0300)
* cord/cordbscs.c (CORD_from_fn): Rename to CORD_from_fn_inner; make it
static; change return type from CORD to CordRep*; define public
CORD_from_fn which simply calls CORD_from_fn_inner (with the type cast
to CORD).
* cord/cordbscs.c (CORD_substr_closure): Call CORD_from_fn_inner
instead of CORD_from_fn (thus remove the cast from const type to
a non-const one).

cord/cordbscs.c

index 3eb63f4..b47cad3 100644 (file)
@@ -278,8 +278,7 @@ CORD CORD_cat(CORD x, CORD y)
 }
 
 
-
-CORD CORD_from_fn(CORD_fn fn, void * client_data, size_t len)
+static CordRep *CORD_from_fn_inner(CORD_fn fn, void * client_data, size_t len)
 {
     if (len == 0) return(0);
     if (len <= SHORT_LIMIT) {
@@ -298,7 +297,7 @@ CORD CORD_from_fn(CORD_fn fn, void * client_data, size_t len)
         if (result == 0) OUT_OF_MEMORY;
         memcpy(result, buf, len);
         result[len] = '\0';
-        return((CORD) result);
+        return (CordRep *)result;
     }
   gen_case:
     {
@@ -311,10 +310,15 @@ CORD CORD_from_fn(CORD_fn fn, void * client_data, size_t len)
         result->len = len;
         result->fn = fn;
         result->client_data = client_data;
-        return((CORD) result);
+        return (CordRep *)result;
     }
 }
 
+CORD CORD_from_fn(CORD_fn fn, void * client_data, size_t len)
+{
+    return (/* const */ CORD) CORD_from_fn_inner(fn, client_data, len);
+}
+
 size_t CORD_len(CORD x)
 {
     if (x == 0) {
@@ -356,7 +360,7 @@ CORD CORD_substr_closure(CORD x, size_t i, size_t n, CORD_fn f)
     if (sa == 0) OUT_OF_MEMORY;
     sa->sa_cord = (CordRep *)x;
     sa->sa_index = i;
-    result = (CordRep *)CORD_from_fn(f, (void *)sa, n);
+    result = CORD_from_fn_inner(f, (void *)sa, n);
     if ((CORD)result != CORD_EMPTY && 0 == result -> function.null)
         result -> function.header = SUBSTR_HDR;
     return (CORD)result;