uninitialized variables checked. Also change two if/else if functions for switch
authorcompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Mon, 9 Aug 2004 00:19:47 +0000 (00:19 +0000)
committercompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Mon, 9 Aug 2004 00:19:47 +0000 (00:19 +0000)
git-svn-id: http://ltt.polymtl.ca/svn@684 04897980-b3bd-0310-b5e0-8ef037075253

ltt/branches/poly/ltt/convert/convert.c
ltt/branches/poly/ltt/event.c
ltt/branches/poly/ltt/facility.c
ltt/branches/poly/ltt/trace.h
ltt/branches/poly/ltt/tracefile.c

index 760eba6d863340c3800df2b50242829299388970..efacdcb630690bcc464689a7d3d82a9f2e4d5957 100644 (file)
@@ -99,9 +99,9 @@ int main(int argc, char ** argv){
   char hardware_platform[BUFFER_SIZE];
   char operating_system[BUFFER_SIZE];
   int  cpu;
-  int  ltt_block_size;
-  int  ltt_major_version;
-  int  ltt_minor_version;
+  int  ltt_block_size=0;
+  int  ltt_major_version=0;
+  int  ltt_minor_version=0;
   int  ltt_log_cpu;
   char buf[BUFFER_SIZE];
   int i, k;
index e4cdfc77a28577322dca9f91bfa93863b2110380..82d57ffcaa9a2468062b58ff815e748534a597d4 100644 (file)
@@ -59,6 +59,58 @@ int ltt_event_refresh_fields(int offsetRoot,int offsetParent,
   int size, size1, element_number, i, offset1, offset2;
   LttType * type = fld->field_type;
 
+  switch(type->type_class) {
+    case LTT_ARRAY:
+      element_number = (int) type->element_number;
+      if(fld->field_fixed == 0){// has string or sequence
+        size = 0;
+        for(i=0;i<element_number;i++){
+          size += ltt_event_refresh_fields(offsetRoot+size,size, 
+             fld->child[0], evD+size);
+        }
+      }else size = fld->field_size;
+      break;
+
+    case LTT_SEQUENCE:
+      size1 = fld->sequ_number_size;
+      element_number = getIntNumber(size1,evD);
+      type->element_number = element_number;
+      if(fld->element_size > 0){
+        size = element_number * fld->element_size;
+      }else{//sequence has string or sequence
+        size = 0;
+        for(i=0;i<element_number;i++){
+          size += ltt_event_refresh_fields(offsetRoot+size+size1,size+size1, 
+                   fld->child[0], evD+size+size1);
+        }      
+        size += size1;
+      }
+      break;
+
+    case LTT_STRING:
+      size = strlen((char*)evD) + 1; //include end : '\0'
+      break;
+
+    case LTT_STRUCT:
+      element_number = (int) type->element_number;
+      if(fld->field_fixed == 0){
+        offset1 = offsetRoot;
+        offset2 = 0;
+        for(i=0;i<element_number;i++){
+          size=ltt_event_refresh_fields(offset1,offset2,
+                                        fld->child[i],evD+offset2);
+          offset1 += size;
+          offset2 += size;
+        }      
+        size = offset2;
+      }else size = fld->field_size;
+      break;
+
+    default:
+      size = fld->field_size;
+  }
+
+#if 0
   if(type->type_class != LTT_STRUCT && type->type_class != LTT_ARRAY &&
      type->type_class != LTT_SEQUENCE && type->type_class != LTT_STRING){
     size = fld->field_size;
@@ -67,9 +119,9 @@ int ltt_event_refresh_fields(int offsetRoot,int offsetParent,
     if(fld->field_fixed == 0){// has string or sequence
       size = 0;
       for(i=0;i<element_number;i++){
-       size += ltt_event_refresh_fields(offsetRoot+size,size, 
+             size += ltt_event_refresh_fields(offsetRoot+size,size, 
                                         fld->child[0], evD+size);
-      }      
+      }
     }else size = fld->field_size;
   }else if(type->type_class == LTT_SEQUENCE){
     size1 = fld->sequ_number_size;
@@ -80,8 +132,8 @@ int ltt_event_refresh_fields(int offsetRoot,int offsetParent,
     }else{//sequence has string or sequence
       size = 0;
       for(i=0;i<element_number;i++){
-       size += ltt_event_refresh_fields(offsetRoot+size+size1,size+size1, 
-                                        fld->child[0], evD+size+size1);
+             size += ltt_event_refresh_fields(offsetRoot+size+size1,size+size1, 
+                                        fld->child[0], evD+size+size1);
       }        
       size += size1;
     }
@@ -93,14 +145,15 @@ int ltt_event_refresh_fields(int offsetRoot,int offsetParent,
       offset1 = offsetRoot;
       offset2 = 0;
       for(i=0;i<element_number;i++){
-       size=ltt_event_refresh_fields(offset1,offset2,fld->child[i],evD+offset2);
-       offset1 += size;
-       offset2 += size;
+             size=ltt_event_refresh_fields(offset1,offset2,
+                                      fld->child[i],evD+offset2);
+       offset1 += size;
+       offset2 += size;
       }      
       size = offset2;
     }else size = fld->field_size;
   }
-
+#endif //0
   fld->offset_root     = offsetRoot;
   fld->offset_parent   = offsetParent;
   fld->fixed_root      = (offsetRoot==-1)   ? 0 : 1;
@@ -637,7 +690,7 @@ float ltt_event_get_float(LttEvent *e, LttField *f)
     guint32 aInt;
     memcpy((void*)&aInt, e->data + f->offset_root, 4);
     aInt = ___swab32(aInt);
-    return *((float*)&aInt);
+    return ((float)aInt);
   }
 }
 
@@ -653,7 +706,7 @@ double ltt_event_get_double(LttEvent *e, LttField *f)
     guint64 aInt;
     memcpy((void*)&aInt, e->data + f->offset_root, 8);
     aInt = ___swab64(aInt);
-    return *((double *)&aInt);
+    return ((double)aInt);
   }
 }
 
index f8e8962ffdb089e33e8b4508d57e1f178cd232aa..55077aa3d1d713b529d8f561791bcfdd68e2827a 100644 (file)
@@ -286,17 +286,18 @@ void constructTypeAndFields(LttFacility * fac,type_descriptor * td,
 LttType * lookup_named_type(LttFacility *fac, type_descriptor * td)
 {
   LttType * lttType = NULL;
-  unsigned int i;
+  unsigned int i=0;
   char * name;
+
   if(td->type_name){
     for(i=0;i<fac->named_types_number; i++){
       if(fac->named_types[i] == NULL) break;
       name = fac->named_types[i]->type_name;
       if(strcmp(name, td->type_name)==0){
-       lttType = fac->named_types[i];  
+             lttType = fac->named_types[i];    
        //      if(lttType->element_name) g_free(lttType->element_name);
        //      lttType->element_name = NULL;
-       break;  
+             break;    
       }
     }
   }
@@ -313,7 +314,7 @@ LttType * lookup_named_type(LttFacility *fac, type_descriptor * td)
     lttType->element_name = NULL;
     if(td->type_name){
       lttType->type_name = g_strdup(td->type_name);
-      fac->named_types[i] = lttType;
+      fac->named_types[i] = lttType; /* i is initialized, checked. */
     }
     else{
       lttType->type_name = NULL;
@@ -516,7 +517,7 @@ LttEventType *ltt_facility_eventtype_get(LttFacility *f, unsigned i)
  *                     : obtain the event type according to event name
  *                       event name is unique in the facility
  *Input params
- *    f                : the facility that will be closed
+ *    f                : the facility
  *    name             : the name of the event
  *Return value
  *    LttEventType *  : the event type required  
@@ -525,13 +526,15 @@ LttEventType *ltt_facility_eventtype_get(LttFacility *f, unsigned i)
 LttEventType *ltt_facility_eventtype_get_by_name(LttFacility *f, char *name)
 {
   unsigned int i;
-  LttEventType * ev;
+  LttEventType * ev = NULL;
+  
   for(i=0;i<f->event_number;i++){
-    ev = f->events[i];
-    if(strcmp(ev->name, name) == 0)break;      
+    LttEventType *iter_ev = f->events[i];
+    if(strcmp(iter_ev->name, name) == 0) {
+      ev = iter_ev;
+      break;
+    }
   }
-
-  if(i==f->event_number) return NULL;
-  else return ev;
+  return ev;
 }
 
index 448ea7975941c7c33dc8093bda8ef02c980e272c..8b4fd197e0548d01618a574246de777bbc4a3f7d 100644 (file)
@@ -151,7 +151,7 @@ void getDataEndianType(LttArchSize * size, LttArchEndian * endian);
 
 /* get an integer number */
 
-int getIntNumber(int size1, void *evD);
+gint64 getIntNumber(int size1, void *evD);
 
 
 /* get the node name of the system */
index 1480546a544f0e22df44f81931e919de3c33d187..f244a48009a7cfef9e65ccfcb70b07bb19566614 100644 (file)
@@ -681,16 +681,20 @@ unsigned ltt_trace_eventtype_number(LttTrace *t)
 
 LttFacility * ltt_trace_facility_by_id(LttTrace * trace, unsigned id)
 {
-  LttFacility * facility;
+  LttFacility * facility = NULL;
   unsigned int i;
+
   for(i=0;i<trace->facility_number;i++){
-    facility = (LttFacility*) g_ptr_array_index(trace->facilities,i);
-    if(id >= facility->base_id && 
-       id < facility->base_id + facility->event_number)
+    LttFacility *iter_facility =
+                      (LttFacility*) g_ptr_array_index(trace->facilities,i);
+    if(id >= iter_facility->base_id && 
+       id < iter_facility->base_id + iter_facility->event_number) {
+      facility = iter_facility;
       break;
+    }
   }
-  if(i==trace->facility_number) return NULL;
-  else return facility;
+
+  return facility;
 }
 
 LttEventType *ltt_trace_eventtype_get(LttTrace *t, unsigned evId)
@@ -1360,6 +1364,107 @@ int getFieldtypeSize(LttTracefile * t, LttEventType * evT, int offsetRoot,
     if(fld == evT->root_field) return fld->field_size;
   }     
 
+  switch(type->type_class) {
+    case LTT_ARRAY:
+      element_number = (int) type->element_number;
+      if(fld->field_fixed == -1){
+        size = getFieldtypeSize(t, evT, offsetRoot,
+                                0,fld->child[0], NULL, trace);
+        if(size == 0){ //has string or sequence
+          fld->field_fixed = 0;
+        }else{
+          fld->field_fixed = 1;
+          size *= element_number; 
+        }
+      }else if(fld->field_fixed == 0){// has string or sequence
+        size = 0;
+        for(i=0;i<element_number;i++){
+          size += getFieldtypeSize(t, evT, offsetRoot+size,size, 
+          fld->child[0], evD+size, trace);
+        }
+      }else size = fld->field_size;
+      break;
+
+    case LTT_SEQUENCE:
+      size1 = (int) ltt_type_size(trace, type);
+      if(fld->field_fixed == -1){
+        fld->sequ_number_size = size1;
+        fld->field_fixed = 0;
+        size = getFieldtypeSize(t, evT, offsetRoot,
+                                0,fld->child[0], NULL, trace);      
+        fld->element_size = size;
+      }else{//0: sequence
+        element_number = getIntNumber(size1,evD);
+        type->element_number = element_number;
+        if(fld->element_size > 0){
+          size = element_number * fld->element_size;
+        }else{//sequence has string or sequence
+          size = 0;
+          for(i=0;i<element_number;i++){
+            size += getFieldtypeSize(t, evT, offsetRoot+size+size1,size+size1, 
+                                     fld->child[0], evD+size+size1, trace);
+          }
+        }
+        size += size1;
+      }
+      break;
+      
+    case LTT_STRING:
+      size = 0;
+      if(fld->field_fixed == -1){
+        fld->field_fixed = 0;
+      }else{//0: string
+        size = strlen((char*)evD) + 1; //include end : '\0'
+      }
+      break;
+      
+    case LTT_STRUCT:
+      element_number = (int) type->element_number;
+      size = 0;
+      if(fld->field_fixed == -1){      
+        offset1 = offsetRoot;
+        offset2 = 0;
+        for(i=0;i<element_number;i++){
+          size1=getFieldtypeSize(t, evT,offset1,offset2,
+                                 fld->child[i], NULL, trace);
+          if(size1 > 0 && size >= 0){
+            size += size1;
+            if(offset1 >= 0) offset1 += size1;
+              offset2 += size1;
+          }else{
+            size = -1;
+            offset1 = -1;
+            offset2 = -1;
+          }
+        }
+        if(size == -1){
+           fld->field_fixed = 0;
+           size = 0;
+        }else fld->field_fixed = 1;
+      }else if(fld->field_fixed == 0){
+        offset1 = offsetRoot;
+        offset2 = 0;
+        for(i=0;i<element_number;i++){
+          size=getFieldtypeSize(t,evT,offset1,offset2,
+                                fld->child[i],evD+offset2, trace);
+          offset1 += size;
+          offset2 += size;
+        }      
+        size = offset2;
+      }else size = fld->field_size;
+      break;
+
+    default:
+      if(fld->field_fixed == -1){
+        size = (int) ltt_type_size(trace, type);
+        fld->field_fixed = 1;
+      }else size = fld->field_size;
+      break;
+  }
+
+
+
+#if 0
   if(type->type_class != LTT_STRUCT && type->type_class != LTT_ARRAY &&
      type->type_class != LTT_SEQUENCE && type->type_class != LTT_STRING){
     if(fld->field_fixed == -1){
@@ -1448,6 +1553,7 @@ int getFieldtypeSize(LttTracefile * t, LttEventType * evT, int offsetRoot,
       size = offset2;
     }else size = fld->field_size;
   }
+#endif //0
 
   fld->offset_root     = offsetRoot;
   fld->offset_parent   = offsetParent;
@@ -1468,18 +1574,31 @@ int getFieldtypeSize(LttTracefile * t, LttEventType * evT, int offsetRoot,
  *    size            : the size of the integer
  *    evD             : the event data
  *Return value
- *    int             : an integer
+ *    gint64          : a 64 bits integer
  ****************************************************************************/
 
-int getIntNumber(int size, void *evD)
+gint64 getIntNumber(int size, void *evD)
 {
   gint64 i;
+
+  switch(size) {
+    case 1: i = *(gint8 *)evD; break;
+    case 2: i = *(gint16 *)evD; break;
+    case 4: i = *(gint32 *)evD; break;
+    case 8: i = *(gint64 *)evD; break;
+    default: i = *(gint64 *)evD;
+             g_critical("getIntNumber : integer size %d unknown", size);
+             break;
+  }
+
+#if 0
   if(size == 1)      i = *(gint8 *)evD;
   else if(size == 2) i = *(gint16 *)evD;
   else if(size == 4) i = *(gint32 *)evD;
   else if(size == 8) i = *(gint64 *)evD;
-  return (int) i;
+#endif //0
+
+  return (gint64)i;
 }
 
 /*****************************************************************************
This page took 0.033396 seconds and 4 git commands to generate.