OSSP CVS Repository

ossp - Difference in ossp-pkg/rc/rc_script.c versions 1.28 and 1.29
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/rc/rc_script.c 1.28 -> 1.29

--- rc_script.c  2003/05/28 14:25:56     1.28
+++ rc_script.c  2003/06/13 10:53:53     1.29
@@ -49,9 +49,13 @@
     rc_script_t *pNew = NULL;
 
     pNew = (rc_script_t *)malloc(sizeof(rc_script_t));
-    *pNew = malloc((strlen(scriptTostring(pOrig)) + 1) * sizeof(char));
-    if (pNew)
-        strcpy(*pNew, scriptTostring(pOrig));
+    if (pNew) {
+        *pNew = malloc((strlen(scriptTostring(pOrig)) + 1) * sizeof(char));
+        if (*pNew)
+            strcpy(*pNew, scriptTostring(pOrig));
+        else
+            RC_THROW(RC_ERR_MEM);
+    }
     else
         RC_THROW(RC_ERR_MEM);
 
@@ -67,7 +71,15 @@
     rc_script_t *pScript = NULL;
 
     pScript = (rc_script_t *)malloc(sizeof(rc_script_t));
-    *pScript = NULL;
+    if (pScript) {
+        *pScript = malloc(sizeof(char));
+        if (*pScript)
+            **pScript = NULL;
+        else
+            RC_THROW(RC_ERR_MEM);
+    }
+    else
+        RC_THROW(RC_ERR_MEM);
 
     return(pScript);
 }
@@ -83,34 +95,27 @@
 
     assert(pScript); /* Script parameter must be valid */
 
-    if (!szInbuf) {
+    if (!szInbuf)
         return(RC_THROW(RC_ERR_USE));
-    }
 
     /* Short circuit in case of dumb noop call */
     if (Size == 0)
         return(RC_THROW(RC_OK));
 
-    /* Add 2 to end of nResize to ensure that a \0 precedes any strings */
-    nResize = (*pScript != NULL ? strlen(*pScript) : 0) + Size + 2;
+    /* Add 2 chars to ensure that a \0 precedes any strings */
+    nResize = strlen(*pScript) + Size + sizeof (char) * 2;
     /* Don't trust realloc(3) in this case */
-    if ((pvRealloc = calloc(1, (size_t)nResize)) == NULL) {
+    if ((pvRealloc = calloc(1, (size_t)nResize)) == NULL)
         return(RC_THROW(RC_ERR_MEM));
-    }
 
     /* Coerce strings into one Script again */
-    if (*pScript) {
+    if (*pScript)
         strcpy(pvRealloc, *pScript);
-        strncat(pvRealloc, szInbuf, Size);
-    }
-    else
-        strncpy(pvRealloc, szInbuf, Size);
+    strncat(pvRealloc, szInbuf, Size);
 
     /* Cleanup and deallocate memory */
-    if (*pScript) {
+    if (*pScript)
         free(*pScript);
-        *pScript = NULL;
-    }
     *pScript = pvRealloc;
 
     return(RC_THROW(RC_OK));
@@ -293,10 +298,10 @@
 {
     /* Don't remove this! It encapsulates the script object, */
     /*                    which might not be a simple string */
-    if (pScript)
+    if (pScript && *pScript)
         return(*pScript);
     else
-        return(NULL);
+        RC_THROW(RC_ERR_USE); /* Script was never constructed */
 }
 
 /************************************************
@@ -308,7 +313,7 @@
     /* Don't remove this! It encapsulates the script object, */
     /*                    which might not be a simple string */
     if (pScript) {
-        fprintf(stdout, "%s", *pScript);
+        fprintf(stdout, "%s", scriptTostring(pScript));
         return(RC_THROW(RC_OK));
     }
     else
@@ -333,7 +338,7 @@
     /* Don't remove this! It encapsulates the script object, */
     /*                    which might not be a simple string */
     if (pStream) {
-        fprintf(pStream, "%s", *pScript);
+        fprintf(pStream, "%s", scriptTostring(pScript));
         fclose(pStream);
         return(RC_THROW(RC_OK));
     }
@@ -347,12 +352,17 @@
 ************************************************/
 rc_return_t scriptDelete(rc_script_t *pScript)
 {
-    if (*pScript)
+    assert(pScript); /* Check for a valid incoming script */
+
+    if (*pScript) {
         free(*pScript);
-    else {
-        RC_THROW(RC_WRN_NUL);
+        *pScript = NULL;
     }
+    else
+        RC_THROW(RC_WRN_NUL);
+
     free(pScript);
+    pScript = NULL;
 
     return(RC_THROW(RC_OK));
 }

CVSTrac 2.0.1