[cvs-annodex] commit (/annodex): libcmml/trunk/doc/cmml-fix.1 libcmml/trunk/doc/cmml-fortune.6 libcmml/trunk/doc/cmml-validate.1 libcmml/trunk/src/cmml_element.c libcmml/trunk/src/cmml_private.c libcmml/trunk/src/cmml_time.c

silvia nobody at lists.annodex.net
Tue Apr 5 21:40:18 EST 2005


Update of /annodex (new revision 1213)

Modified files:
   libcmml/trunk/doc/cmml-fix.1
   libcmml/trunk/doc/cmml-fortune.6
   libcmml/trunk/doc/cmml-validate.1
   libcmml/trunk/src/cmml_element.c
   libcmml/trunk/src/cmml_private.c
   libcmml/trunk/src/cmml_time.c

Log Message:
Fixed a malloc problem that was caused by an unitialised allocated
data block in the time parsing.
Replaced malloc with calloc, which fixed it.
But also corrected the initialisation code.
Also streamlined the cmml_malloc calls.



Modified: libcmml/trunk/doc/cmml-fix.1
===================================================================
--- libcmml/trunk/doc/cmml-fix.1	2005-04-04 05:40:40 UTC (rev 1212)
+++ libcmml/trunk/doc/cmml-fix.1	2005-04-05 11:40:18 UTC (rev 1213)
@@ -1,4 +1,4 @@
-.\" $Header: /var/lib/cvsd/annodex/libcmml/doc/cmml-fix.1,v 1.5 2004/03/11 01:47:22 silvia Exp $
+.\" $Header: /aolnet/dev/src/CVS/sgml/docbook-to-man/cmd/docbook-to-man.sh,v 1.1.1.1 1998/11/13 21:31:59 db3l Exp $
 .\"
 .\"	transcript compatibility for postscript use.
 .\"
@@ -91,11 +91,11 @@
 Print version information. 
 .SH "VERSION" 
 .PP 
-This man page is correct for CMML version 2.0 and libcmml 
-version 0.8.2. 
+This man page is correct for CMML version 2.1 and libcmml 
+version 0.9.0. 
  
 .SH "SEE ALSO" 
 .PP 
 More information is available at: 
 \fIAnnodex.net (link to URL http://www.annodex.net/) \fR    
-.\" created by instant / docbook-to-man, Thu 11 Mar 2004, 13:45 
+.\" created by instant / docbook-to-man, Tue 05 Apr 2005, 20:16 

Modified: libcmml/trunk/doc/cmml-fortune.6
===================================================================
--- libcmml/trunk/doc/cmml-fortune.6	2005-04-04 05:40:40 UTC (rev 1212)
+++ libcmml/trunk/doc/cmml-fortune.6	2005-04-05 11:40:18 UTC (rev 1213)
@@ -1,4 +1,4 @@
-.\" $Header: /var/lib/cvsd/annodex/libcmml/doc/cmml-fortune.6,v 1.5 2004/03/11 01:47:22 silvia Exp $
+.\" $Header: /aolnet/dev/src/CVS/sgml/docbook-to-man/cmd/docbook-to-man.sh,v 1.1.1.1 1998/11/13 21:31:59 db3l Exp $
 .\"
 .\"	transcript compatibility for postscript use.
 .\"
@@ -98,11 +98,11 @@
 Display version information and exit. 
 .SH "VERSION" 
 .PP 
-This man page is correct for CMML version 2.0 and libcmml 
-version 0.8.2. 
+This man page is correct for CMML version 2.1 and libcmml 
+version 0.9.0. 
  
 .SH "SEE ALSO" 
 .PP 
 More information is available at 
 \fIAnnodex.net (link to URL http://www.annodex.net/) \fR      
-.\" created by instant / docbook-to-man, Thu 11 Mar 2004, 13:45 
+.\" created by instant / docbook-to-man, Tue 05 Apr 2005, 20:16 

Modified: libcmml/trunk/doc/cmml-validate.1
===================================================================
--- libcmml/trunk/doc/cmml-validate.1	2005-04-04 05:40:40 UTC (rev 1212)
+++ libcmml/trunk/doc/cmml-validate.1	2005-04-05 11:40:18 UTC (rev 1213)
@@ -1,4 +1,4 @@
-.\" $Header: /var/lib/cvsd/annodex/libcmml/doc/cmml-validate.1,v 1.5 2004/03/11 01:47:22 silvia Exp $
+.\" $Header: /aolnet/dev/src/CVS/sgml/docbook-to-man/cmd/docbook-to-man.sh,v 1.1.1.1 1998/11/13 21:31:59 db3l Exp $
 .\"
 .\"	transcript compatibility for postscript use.
 .\"
@@ -91,11 +91,11 @@
 Print version information. 
 .SH "VERSION" 
 .PP 
-This man page is correct for CMML version 2.0 and libcmml 
-version 0.8.2. 
+This man page is correct for CMML version 2.1 and libcmml 
+version 0.9.0. 
  
 .SH "SEE ALSO" 
 .PP 
 More information is available at: 
 \fIAnnodex.net (link to URL http://www.annodex.net/) \fR      
-.\" created by instant / docbook-to-man, Thu 11 Mar 2004, 13:45 
+.\" created by instant / docbook-to-man, Tue 05 Apr 2005, 20:16 

Modified: libcmml/trunk/src/cmml_element.c
===================================================================
--- libcmml/trunk/src/cmml_element.c	2005-04-04 05:40:40 UTC (rev 1212)
+++ libcmml/trunk/src/cmml_element.c	2005-04-05 11:40:18 UTC (rev 1213)
@@ -96,7 +96,7 @@
 CMML_Element *
 cmml_element_new(CMML_Element_Type type)
 {
-  CMML_Element * elem = cmml_malloc(sizeof(*elem));
+  CMML_Element * elem = cmml_malloc(sizeof(CMML_Element));
   
   switch (type) {
   case CMML_STREAM:
@@ -209,7 +209,7 @@
 
   if (param == NULL) return NULL;
 
-  new_param = (CMML_ParamElement* ) cmml_malloc (sizeof (CMML_ParamElement));
+  new_param = (CMML_ParamElement* ) cmml_malloc (sizeof(CMML_ParamElement));
   /* maybe consider memcpy for speedup and introduce reference counting!
      memcpy (new_param, param, sizeof (*new_param));
      -> NO: may introduce a problem with byte alignment
@@ -225,7 +225,7 @@
 {
   CMML_ImportElement * new_import;
   if (import == NULL) return NULL;
-  new_import = (CMML_ImportElement*) cmml_malloc (sizeof (CMML_ImportElement));
+  new_import = (CMML_ImportElement*) cmml_malloc (sizeof(CMML_ImportElement));
   new_import->id          = cmml_strdup (import->id);
   new_import->lang        = cmml_strdup (import->lang);
   new_import->dir         = cmml_strdup (import->dir);
@@ -248,7 +248,7 @@
 
   if (meta == NULL) return NULL;
 
-  new_meta = (CMML_MetaElement* ) cmml_malloc (sizeof (CMML_MetaElement));
+  new_meta = (CMML_MetaElement* ) cmml_malloc (sizeof(CMML_MetaElement));
   /* maybe consider memcpy for speedup and introduce reference counting!
      memcpy (new_meta, meta, sizeof (*new_meta));
   */
@@ -268,7 +268,7 @@
 
   if (link == NULL) return NULL;
 
-  new_link = (CMML_LinkElement* ) cmml_malloc (sizeof (CMML_LinkElement));
+  new_link = (CMML_LinkElement* ) cmml_malloc (sizeof(CMML_LinkElement));
   /* maybe consider memcpy for speedup and introduce reference counting!
      memcpy (new_link, link, sizeof (*new_link));
   */
@@ -335,7 +335,7 @@
 {
   CMML_Stream * s;
   if (src == NULL) return NULL;
-  s = (CMML_Stream *) cmml_malloc (sizeof (CMML_Stream));
+  s = (CMML_Stream *) cmml_malloc(sizeof(CMML_Stream));
   /*
   memcpy (s, src, sizeof (*s));
   */
@@ -357,7 +357,7 @@
   CMML_Head * new_head;
 
   if (head == NULL) return NULL;
-  new_head = (CMML_Head *) cmml_malloc (sizeof (CMML_Head));
+  new_head = (CMML_Head *) cmml_malloc(sizeof(CMML_Head));
   /*
   memcpy (new_head, head, sizeof (*new_head));
   */
@@ -383,7 +383,7 @@
 {
   CMML_Clip * a;
   if (src == NULL) return NULL;
-  a = (CMML_Clip *) cmml_malloc (sizeof (CMML_Clip));
+  a = (CMML_Clip *) cmml_malloc(sizeof(CMML_Clip));
   /*
   memcpy (a, src, sizeof (*a));
   */

Modified: libcmml/trunk/src/cmml_private.c
===================================================================
--- libcmml/trunk/src/cmml_private.c	2005-04-04 05:40:40 UTC (rev 1212)
+++ libcmml/trunk/src/cmml_private.c	2005-04-05 11:40:18 UTC (rev 1213)
@@ -207,7 +207,8 @@
   int i;
   CMML_ImportElement * m;
 
-  if ((m = cmml_malloc(sizeof(*m))) == NULL) return import_list;
+  if ((m = (CMML_ImportElement *) cmml_malloc(sizeof(CMML_ImportElement))) 
+      == NULL) return import_list;
   m->id   = NULL;
   m->lang = NULL;
   m->dir  = NULL;
@@ -298,7 +299,8 @@
   }
 
   /* create new param_element and insert it */
-  if((p = cmml_malloc(sizeof(*p))) == NULL) return import_list;
+  if((p = (CMML_ParamElement *) cmml_malloc(sizeof(CMML_ParamElement)))
+     == NULL) return import_list;
   p->id = NULL;
   p->name = NULL;
   p->value = NULL;
@@ -422,7 +424,8 @@
   int i;
   CMML_MetaElement * m;
 
-  if((m = cmml_malloc(sizeof(*m))) == NULL) return NULL;
+  if((m = (CMML_MetaElement *) cmml_malloc(sizeof(CMML_MetaElement)))
+     == NULL) return NULL;
   m->id = NULL;
   m->lang = NULL;
   m->dir = NULL;
@@ -475,7 +478,8 @@
     return NULL;
   } 
   
-  if ((l = cmml_malloc(sizeof(*l))) == NULL) return NULL;
+  if ((l = (CMML_LinkElement *) cmml_malloc(sizeof(CMML_LinkElement)))
+      == NULL) return NULL;
   l->id = NULL;
   l->class = NULL;
   l->title = NULL;
@@ -1341,7 +1345,7 @@
 {
   /* allocate context */
   CMML_Context * context;
-  context = cmml_malloc(sizeof(CMML_Context));
+  context = (CMML_Context *) cmml_malloc(sizeof(CMML_Context));
 
   /* fill context fields */
   context->file = file;
@@ -1349,16 +1353,16 @@
   context->parser = XML_ParserCreate(NULL); 
   XML_SetUserData(context->parser, context);
   context->sloppy_parsing = 0;
-  context->cdata = cmml_malloc(sizeof(CMML_DataBuf));
-  context->cdata->base = cmml_malloc(INIT_DATA_BUF_SIZE);
+  context->cdata = (CMML_DataBuf *) cmml_malloc(sizeof(CMML_DataBuf));
+  context->cdata->base = (XML_Char *) cmml_malloc(sizeof(XML_Char)*INIT_DATA_BUF_SIZE + 1);
   *(context->cdata->base) = '\0';
   context->cdata->limit = INIT_DATA_BUF_SIZE;
   context->read_stream = NULL;
   context->read_head   = NULL;
   context->read_clip = NULL;
   context->user_data = NULL;
-  context->status = cmml_malloc(sizeof(CMML_Status));
-  context->status->info = cmml_malloc(sizeof(CMML_Preamble));
+  context->status = (CMML_Status *) cmml_malloc(sizeof(CMML_Status));
+  context->status->info = (CMML_Preamble *) cmml_malloc(sizeof(CMML_Preamble));
   context->status->info->xml_version      = NULL;
   context->status->info->xml_encoding     = NULL;
   context->status->info->xml_standalone   = -2;
@@ -1456,7 +1460,7 @@
 {
     void *p;
     
-    p = malloc(size);
+    p = calloc(1,size);
     if (!p) {
         fprintf(stderr, "libcmml: memory allocation error.");
         exit(1);
@@ -1517,7 +1521,7 @@
   }
 
   /* copy string changing characters */
-  retstr = cmml_malloc (len*sizeof(char)+1);
+  retstr = (char *) cmml_malloc (len*sizeof(char)+1);
   j=0;
   for (i=0,c=instr[0]; c!='\0'; c=instr[++i]) {
     switch (c) {

Modified: libcmml/trunk/src/cmml_time.c
===================================================================
--- libcmml/trunk/src/cmml_time.c	2005-04-04 05:40:40 UTC (rev 1212)
+++ libcmml/trunk/src/cmml_time.c	2005-04-05 11:40:18 UTC (rev 1213)
@@ -112,14 +112,14 @@
 
   n = sscanf (str, "%d:%d:%f",  &h, &m, &s);
   if (n == 3) {
-    goto done;
+    goto pdone;
   }
 
   /* this is not really according to spec, but we tolerate it */
   n = sscanf (str, "%d:%f",  &m, &s);
   if (n == 2) {
     h = 0;
-    goto done;
+    goto pdone;
   }
 
   /* this gets activated even if there is more that just a float in
@@ -127,19 +127,19 @@
   n = sscanf (str, "%f", &s);
   if (n == 1) {
     h = 0; m = 0;
-    goto sec_only;
+    goto psec_only;
   }
   
   /* this only gets activated if there is no number in the string */
   return NULL;
 
- done:
+ pdone:
   /* check valid time specs */
   if (h<0) return NULL;
   if (m>59 || m<0) return NULL;
   if (s>=60.0 || s<0.0) return NULL;
 
-  fixed_string = (char *) cmml_malloc (16);
+  fixed_string = (char *) cmml_malloc (32);
   /* %0 make leading 0s go away (zero padding) */
   /* %2 provides a minimum field width */
   /* %-1 makes left adjustment */
@@ -152,9 +152,9 @@
   }
   return fixed_string;
 
- sec_only:
+ psec_only:
   /* XXX fix this: calculate the length properly */
-  fixed_string = (char *) cmml_malloc (16);
+  fixed_string = (char *) cmml_malloc (32);
   sprintf (fixed_string, "%.3f", s);
   return fixed_string;;
 }
@@ -189,16 +189,23 @@
     speclen = 4;
     fix_timespec = fix_npt_str (str+speclen);
   } else {
+    speclen = 0;
     fix_timespec = fix_npt_str (str);
   }
   if (fix_timespec == NULL) return NULL;
-  full_timespec = (char *) cmml_malloc (strlen(fix_timespec)+speclen);
+  full_timespec = (char *) cmml_malloc(strlen(fix_timespec)+speclen+1);
   if (speclen > 0) {
     strncpy(full_timespec, "npt:", 4);
   }
+  /* null-terminate the string */
+  full_timespec[speclen] = '\0';
+  /* append the time */
   strcat(full_timespec, fix_timespec);
+#ifdef DEBUG
+  fprintf(stderr,"full_timespec  = %s\n", full_timespec);
+#endif
+
   return full_timespec;
-
 }
 
 /* parse_smpte: INLINE function to parse a smpte-string */
@@ -253,7 +260,7 @@
 cmml_sec_new (const char * s)
 {
   CMML_Time * t;
-  t = (CMML_Time *) cmml_malloc (sizeof (*t));
+  t = (CMML_Time *) cmml_malloc(sizeof(CMML_Time));
 
 #ifdef DEBUG
   fprintf(stderr, "creating new play time: %s\n", s);
@@ -272,7 +279,7 @@
 cmml_utc_new (const char * s)
 {
   CMML_Time * t;
-  t = (CMML_Time *) cmml_malloc (sizeof (*t));
+  t = (CMML_Time *) cmml_malloc(sizeof(CMML_Time));
 
 #ifdef DEBUG
   fprintf(stderr, "creating new utc time: %s\n", s);
@@ -356,7 +363,7 @@
   } else {
     /* it's a time range */
     len_start_time = (int)(strlen(s) - strlen(pos));
-    start_time = (char *) cmml_malloc (len_start_time+1);
+    start_time = (char *) cmml_malloc(len_start_time+1);
     start_time = strncpy (start_time, s, len_start_time);
     start_time[len_start_time]='\0';
     *t_start = cmml_time_new(start_time);
@@ -386,7 +393,7 @@
       } 
       /* create t_end for the smpte timecodes */
       if (seconds > 0) {
-	*t_end = (CMML_Time *) cmml_malloc (sizeof (CMML_Time));
+	*t_end = (CMML_Time *) cmml_malloc(sizeof(CMML_Time));
 	(*t_end)->tstr = cmml_strdup(pos+1);
 	(*t_end)->type = CMML_SEC_TIME;
 	(*t_end)->t.sec = seconds;
@@ -416,7 +423,7 @@
 {
   CMML_Time * t = NULL;
   if (t1 == NULL) return NULL;
-  t = (CMML_Time*) cmml_malloc (sizeof (CMML_Time));
+  t = (CMML_Time*) cmml_malloc(sizeof(CMML_Time));
   t->tstr = cmml_strdup(t1->tstr);
   t->type = t1->type;
   if (t->type == CMML_UTC_TIME) {
@@ -487,12 +494,12 @@
   int n;
   char tm_year[5], tm_month[3], tm_day[3], tm_hour[3], tm_min[3], tm_sec[3];
 
-  t = (CMML_UTC *) cmml_malloc (sizeof (*t));
+  t = (CMML_UTC *) cmml_malloc(sizeof(CMML_UTC));
 
   /* try parsing and return NULL in case of failure */
   n = sscanf (s, "%4s%2s%2s%*c%2s%2s%2s.%hi", tm_year, tm_month, tm_day, 
               tm_hour, tm_min, tm_sec, &(t->tm_hsec));
-#if 0
+#ifdef DEBUG
   if (n==6 || n==7) fprintf(stderr, "Successfully ");
   fprintf(stderr, "Parsed UTC time: %s\n", s);
   fprintf(stderr, "Year=%4s\tMonth=%2s\tDay=%2s\n", 
@@ -541,7 +548,7 @@
 {
   CMML_UTC * t;
   if (t1 == NULL) return NULL;
-  t = (CMML_UTC *) cmml_malloc (sizeof (*t));
+  t = (CMML_UTC *) cmml_malloc(sizeof(CMML_UTC));
   t->tm_hsec = t1->tm_hsec;
   t->tm_sec  = t1->tm_sec;
   t->tm_min  = t1->tm_min;


-- 
silvia



More information about the cvs-annodex mailing list