OSSP CVS Repository

ossp - Check-in [3473]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 3473
Date: 2003-Jun-30 16:43:36 (local)
2003-Jun-30 14:43:36 (UTC)
User:ms
Branch:
Comment: Replace references to scriptAppend with scriptAdd, and change name of scriptAppend to scriptnAppend to avoid surprises. Also, debug minimal memory overallocation in scriptnAppend.
Tickets:
Inspections:
Files:
ossp-pkg/rc/rc.h      1.52 -> 1.53     2 inserted, 1 deleted
ossp-pkg/rc/rc_file.c      1.3 -> 1.4     1 inserted, 1 deleted
ossp-pkg/rc/rc_proc.c      1.50 -> 1.51     14 inserted, 15 deleted
ossp-pkg/rc/rc_script.c      1.32 -> 1.33     9 inserted, 9 deleted
ossp-pkg/rc/rc_sect.c      1.16 -> 1.17     15 inserted, 5 deleted

ossp-pkg/rc/rc.h 1.52 -> 1.53

--- rc.h 2003/06/27 14:26:13     1.52
+++ rc.h 2003/06/30 14:43:36     1.53
@@ -109,7 +109,7 @@
 rc_script_t *scriptNew(void);
 rc_script_t *scriptCopy(rc_script_t *);
 rc_return_t scriptAdd(rc_script_t *, rc_script_t *);
-rc_return_t scriptAppend(rc_script_t *, const char *, size_t);
+rc_return_t scriptnAppend(rc_script_t *, const char *, size_t);
 rc_section_t *scriptSection(rc_script_t *, const char *);
 rc_return_t scriptDump(rc_script_t *);
 rc_return_t scriptWrite(rc_script_t *, const char *);
@@ -136,6 +136,7 @@
 const char *sectionGetparent(rc_section_t *);
 const char *sectionGetlabel(rc_section_t *);
 const char *sectionGetlogin(rc_section_t *);
+rc_script_t *sectionGetscript(rc_section_t *);
 const char *sectionGetdata(rc_section_t *);
 size_t sectionGetlen(rc_section_t *);
 rc_return_t sectionSetpri(rc_section_t *, long);


ossp-pkg/rc/rc_file.c 1.3 -> 1.4

--- rc_file.c    2003/06/27 14:26:13     1.3
+++ rc_file.c    2003/06/30 14:43:36     1.4
@@ -116,7 +116,7 @@
     pScript = scriptNew();
     sBuf = (char *)calloc(1, RC_READ_BUFSIZE);
     while ((nRet = read(nFdrc, sBuf, RC_READ_BUFSIZE)) > 0)
-        scriptAppend(pScript, sBuf, nRet);
+        scriptnAppend(pScript, sBuf, nRet);
 
     if (nRet == -1) /* Handle read errors */
         RC_THROW(RC_ERR_IO);


ossp-pkg/rc/rc_proc.c 1.50 -> 1.51

--- rc_proc.c    2003/06/27 14:26:13     1.50
+++ rc_proc.c    2003/06/30 14:43:36     1.51
@@ -88,10 +88,10 @@
         if ((nFdfunc = open(configGetval(RC_FNC_VAL), O_RDONLY)) >= 0) {
             /* Read data from the func file */
             while ((nRet = read(nFdfunc, sBuf, RC_READ_BUFSIZE)) > 0)
-                scriptAppend(pRc->m_pScriptfunc, sBuf, nRet);
+                scriptnAppend(pRc->m_pScriptfunc, sBuf, nRet);
             if (nRet == -1) /* Handle read errors */
                 RC_THROW(RC_ERR_IO);
-            scriptAppend(pRc->m_pScriptfunc, "\n", sizeof("\n"));
+            scriptnAppend(pRc->m_pScriptfunc, "\n", sizeof("\n"));
             close(nFdfunc); /* Close Func file handle */
         }
         else
@@ -110,8 +110,8 @@
         try { /* If it exists, append config section unconditionally */
             pSec = rcfileGetsec(pRcfile, configGetval(RC_NCF_VAL));
             if (pSec) { /* Only operate if the section lookup succeeds */
-                scriptAppend(pRc->m_pScriptcnf, sectionGetdata(pSec), strlen(sectionGetdata(pSec)));
-                scriptAppend(pRc->m_pScriptcnf, "\n", strlen ("\n"));
+                scriptAdd(pRc->m_pScriptcnf, sectionGetscript(pSec));
+                scriptnAppend(pRc->m_pScriptcnf, "\n", strlen ("\n"));
             }
 
             for (nSect = 0; nSect < nTotalsecs; nSect++) { /* Iterate over */
@@ -183,13 +183,13 @@
         /* Allocate a block of section pointers to use temporarily */
         ppSectmp = calloc(pRc->m_pList->m_nFiles, sizeof(rc_section_t *));
         pFatscript = scriptNew();
-        scriptAppend(pFatscript, RC_BANG_STR, strlen(RC_BANG_STR)); /* Shebang */
+        scriptnAppend(pFatscript, RC_BANG_STR, strlen(RC_BANG_STR)); /* Shebang */
         /* Conditionally output initial notice in verbal mode */
         if (configGetval(RC_VRB_VAL)) {
             szVerbose = malloc((strlen(RC_VST_TEXT) + 2) * sizeof (char));
             sprintf(szVerbose, "%s", RC_VST_TEXT);
             strcat(szVerbose, "\n");
-            scriptAppend(pFatscript, szVerbose, strlen(szVerbose));
+            scriptnAppend(pFatscript, szVerbose, strlen(szVerbose));
             free(szVerbose);
             szVerbose = NULL;
         }
@@ -198,7 +198,7 @@
             szVerbose = malloc((strlen(RC_EVF_TEXT) + 2) * sizeof (char));
             sprintf(szVerbose, "%s", RC_EVF_TEXT);
             strcat(szVerbose, "\n");
-            scriptAppend(pFatscript, szVerbose, strlen(szVerbose));
+            scriptnAppend(pFatscript, szVerbose, strlen(szVerbose));
             free(szVerbose);
             szVerbose = NULL;
         }
@@ -209,7 +209,7 @@
             szVerbose = malloc(nBytes);
             sprintf(szVerbose, RC_EVN_TEXT, RC_DEF_NCF, RC_DEF_NCF);
             strcat(szVerbose, "\n");
-            scriptAppend(pFatscript, szVerbose, strlen(szVerbose));
+            scriptnAppend(pFatscript, szVerbose, strlen(szVerbose));
             free(szVerbose);
             szVerbose = NULL;
         }
@@ -234,17 +234,16 @@
                     szVerbose = malloc(nBytes);
                     sprintf(szVerbose, RC_EVN_TEXT, szTmp, sectionGetparent(ppSectmp[nTmp]));
                     strcat(szVerbose, "\n");
-                    scriptAppend(pFatscript, szVerbose, strlen(szVerbose));
+                    scriptnAppend(pFatscript, szVerbose, strlen(szVerbose));
                     free(szVerbose);
                     szVerbose = NULL;
                 }
                 if ((szTmp = (char *)sectionGetlogin(ppSectmp[nTmp])) != NULL) {
-                    scriptAppend(pFatscript, "#su ", strlen("#su "));
-                    scriptAppend(pFatscript, szTmp, strlen(szTmp));
-                    scriptAppend(pFatscript, "\n", strlen("\n") + 1);
+                    scriptnAppend(pFatscript, "#su ", strlen("#su "));
+                    scriptnAppend(pFatscript, szTmp, strlen(szTmp));
+                    scriptnAppend(pFatscript, "\n", strlen("\n"));
                 }
-                szTmp = (char *)sectionGetdata(ppSectmp[nTmp]);
-                scriptAppend(pFatscript, szTmp, strlen(szTmp) + 1);
+                scriptAdd(pFatscript, sectionGetscript(ppSectmp[nTmp]));
             }
         }
         free(ppSectmp);
@@ -465,7 +464,7 @@
         /* Allocate a block of section pointers to use as a temporary */
         ppSectmp = calloc(pRc->m_pList->m_nFiles, sizeof(rc_section_t *));
         pBangscript = scriptNew();
-        scriptAppend(pBangscript, RC_BANG_STR, (strlen(RC_BANG_STR) + 1) * sizeof (char));
+        scriptnAppend(pBangscript, RC_BANG_STR, strlen(RC_BANG_STR));
         scriptDump(pBangscript); /* Dump the shebang */
         scriptDelete(pBangscript);
 


ossp-pkg/rc/rc_script.c 1.32 -> 1.33

--- rc_script.c  2003/06/26 18:45:14     1.32
+++ rc_script.c  2003/06/30 14:43:36     1.33
@@ -96,7 +96,7 @@
     assert(pDest && pSource); /* Parameters must be valid */
 
     /* Add 2 chars to ensure that a \0 precedes any strings */
-    nResize = strlen(*pDest) + strlen(*pSource) + sizeof (char) * 2;
+    nResize = strlen(*pDest) + strlen(*pSource) + sizeof (char);
     /* Don't trust realloc(3) in this case */
     if ((pvRealloc = calloc(1, (size_t)nResize)) == NULL)
         return(RC_THROW(RC_ERR_MEM));
@@ -114,11 +114,11 @@
     return(RC_THROW(RC_OK));
 }
 
-/****************************************************
-* scriptAppend(rc_script_t *, const char *, size_t) *
-* Append text to a script                           *
-****************************************************/
-rc_return_t scriptAppend(rc_script_t *pScript, const char *szInbuf, size_t Size)
+/*****************************************************
+* scriptnAppend(rc_script_t *, const char *, size_t) *
+* Append n characters of text to a script            *
+*****************************************************/
+rc_return_t scriptnAppend(rc_script_t *pScript, const char *szInbuf, size_t Size)
 {
     int nResize     = 0;
     void *pvRealloc = NULL;
@@ -133,7 +133,7 @@
         return(RC_THROW(RC_OK));
 
     /* Add 2 chars to ensure that a \0 precedes any strings */
-    nResize = strlen(*pScript) + Size + sizeof (char) * 2;
+    nResize = strlen(*pScript) + Size + sizeof (char);
     /* Don't trust realloc(3) in this case */
     if ((pvRealloc = calloc(1, (size_t)nResize)) == NULL)
         return(RC_THROW(RC_ERR_MEM));
@@ -141,7 +141,7 @@
     /* Coerce strings into one Script again */
     if (*pScript)
         strcpy(pvRealloc, *pScript);
-    strncat(pvRealloc, szInbuf, Size);
+    strncat(pvRealloc, szInbuf, Size + 1);
 
     /* Cleanup and deallocate memory */
     if (*pScript)
@@ -330,7 +330,7 @@
 
     /* Don't remove this! It encapsulates the script object, */
     /*                    which might not be a simple string */
-    return(*pScript);
+    return((const char *)*pScript);
 }
 
 /************************************************


ossp-pkg/rc/rc_sect.c 1.16 -> 1.17

--- rc_sect.c    2003/06/27 14:26:13     1.16
+++ rc_sect.c    2003/06/30 14:43:36     1.17
@@ -159,15 +159,25 @@
     return(0); /* Not reached */
 }
 
+rc_script_t *sectionGetscript(rc_section_t *pSec)
+{
+    if (pSec)
+        return(pSec->m_pData);
+    else
+        RC_THROW(RC_ERR_USE);
+
+    return(0); /* Not reached */
+}
+
 const char *sectionGetdata(rc_section_t *pSec)
 { /* Data of section, this is the script body of the particular section */
-    char *szScriptdata = NULL;
-
-    if (pSec && (szScriptdata = scriptGetdata(pSec->m_pData)))
-        if (strlen(szScriptdata) > 0)
-            return(szScriptdata);
+    if (pSec) {
+        const char *kszScriptdata = scriptGetdata(pSec->m_pData);
+        if (kszScriptdata && strlen(kszScriptdata) > 0)
+            return(kszScriptdata);
         else
             return NULL;
+    }
     else
         RC_THROW(RC_ERR_USE);
 

CVSTrac 2.0.1