Index: ossp-pkg/rc/rc_script.c RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_script.c,v rcsdiff -q -kk '-r1.28' '-r1.29' -u '/v/ossp/cvs/ossp-pkg/rc/rc_script.c,v' 2>/dev/null --- 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)); } Index: ossp-pkg/rc/rc_test.sh RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_test.sh,v rcsdiff -q -kk '-r1.25' '-r1.26' -u '/v/ossp/cvs/ossp-pkg/rc/rc_test.sh,v' 2>/dev/null --- rc_test.sh 2003/06/12 14:24:15 1.25 +++ rc_test.sh 2003/06/13 10:53:53 1.26 @@ -98,9 +98,11 @@ read dummy;clear # Some examples using fake rc files and REAL ONES AS WELL, use with care! -echo "The following test will execute test suite code," -echo "and code ALSO FROM YOUR REAL OPENPKG RC FILES!!!" -echo "If this concerns you, then press Ctrl-C now to exit." +echo "******************************************************" +echo "*The following test will execute test suite code, *" +echo "*and code ALSO FROM YOUR REAL OPENPKG RC FILES!!! *" +echo "*If this concerns you, then press Ctrl-C now to exit.*" +echo "******************************************************" echo; echo "" read dummy;clear echo "./rc --conf $RCBASE/rc.conf --ParseSectionDef \"^%(\w+)[ \t]*(.*?)\n(.*?)^$\" --locate $RCBASE/rc.d:./rc_test:/etc/rc --query all barf test"