OSSP CVS Repository

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

ossp-pkg/rc/rc_sect.c 1.1 -> 1.2

--- rc_sect.c    2002/08/02 16:38:09     1.1
+++ rc_sect.c    2003/04/03 12:05:14     1.2
@@ -28,6 +28,7 @@
 */
 
 #include <string.h> /* For string copy and such data ops */
+#include <stdlib.h> /* For memory ops */
 
 #include "rc.h"     /* Public Rc interface */
 
@@ -42,8 +43,10 @@
 
     /* Among other things, they make great coffee at Cable & Wireless */
     /* This code would probably have more bugs if the coffee was not as good */
-    pSec = (rc_section_t *)malloc(sizeof(rc_section_t));
-    *pSec = NULL;
+    pSec = (rc_section_t *)calloc(1, sizeof(rc_section_t));
+
+    if (!pSec)
+        RC_THROW(RC_ERR_MEM);
 
     return(pSec);
 }
@@ -82,6 +85,16 @@
     return(0); /* Not reached */
 }
 
+size_t sectionGetlen(rc_section_t *pSec)
+{ /* Data length of section, length of a script body of a particular section */
+    if (pSec)
+        return(pSec->Bytes);
+    else
+        RC_THROW(RC_ERR_USE);
+
+    return(0); /* Not reached */
+}
+
 /************************************************
 * sectionSetXXX(rc_section_t *)                 *
 * Accessor methods                              *
@@ -109,13 +122,14 @@
 rc_return_t sectionSetdata(rc_section_t *pSec, const char *kszScript)
 { /* Data of section, this is the script body of the particular section */
     if (pSec) {
+        pSec->Bytes = strlen(kszScript) + sizeof(char); /* Calculate size */
         if (pSec->szData) { /* The section data is already in use */
             free(pSec->szData);
-            pSec->szData = malloc(strlen(kszScript) + sizeof(char));
+            pSec->szData = malloc(pSec->szData);
             strcpy(pSec->szData, kszScript);
         }
         else { /* Set the data the usual way */
-            pSec->szData = malloc(strlen(kszScript) + sizeof(char));
+            pSec->szData = malloc(pSec->szData);
             strcpy(pSec->szData, kszScript);
         }
         return(RC_THROW(RC_OK));

CVSTrac 2.0.1