From cf74a6f1dc8fdeb7f7216d1c22f89fff405f9df1 Mon Sep 17 00:00:00 2001 From: compudj Date: Mon, 9 Aug 2004 00:19:47 +0000 Subject: [PATCH] uninitialized variables checked. Also change two if/else if functions for switch git-svn-id: http://ltt.polymtl.ca/svn@684 04897980-b3bd-0310-b5e0-8ef037075253 --- ltt/branches/poly/ltt/convert/convert.c | 6 +- ltt/branches/poly/ltt/event.c | 73 +++++++++++-- ltt/branches/poly/ltt/facility.c | 25 +++-- ltt/branches/poly/ltt/trace.h | 2 +- ltt/branches/poly/ltt/tracefile.c | 139 ++++++++++++++++++++++-- 5 files changed, 210 insertions(+), 35 deletions(-) diff --git a/ltt/branches/poly/ltt/convert/convert.c b/ltt/branches/poly/ltt/convert/convert.c index 760eba6d..efacdcb6 100644 --- a/ltt/branches/poly/ltt/convert/convert.c +++ b/ltt/branches/poly/ltt/convert/convert.c @@ -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; diff --git a/ltt/branches/poly/ltt/event.c b/ltt/branches/poly/ltt/event.c index e4cdfc77..82d57ffc 100644 --- a/ltt/branches/poly/ltt/event.c +++ b/ltt/branches/poly/ltt/event.c @@ -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;ichild[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;ichild[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;ichild[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;ichild[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;ichild[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;ichild[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); } } diff --git a/ltt/branches/poly/ltt/facility.c b/ltt/branches/poly/ltt/facility.c index f8e8962f..55077aa3 100644 --- a/ltt/branches/poly/ltt/facility.c +++ b/ltt/branches/poly/ltt/facility.c @@ -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;inamed_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;ievent_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; } diff --git a/ltt/branches/poly/ltt/trace.h b/ltt/branches/poly/ltt/trace.h index 448ea797..8b4fd197 100644 --- a/ltt/branches/poly/ltt/trace.h +++ b/ltt/branches/poly/ltt/trace.h @@ -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 */ diff --git a/ltt/branches/poly/ltt/tracefile.c b/ltt/branches/poly/ltt/tracefile.c index 1480546a..f244a480 100644 --- a/ltt/branches/poly/ltt/tracefile.c +++ b/ltt/branches/poly/ltt/tracefile.c @@ -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;ifacility_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;ichild[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;ichild[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;ichild[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;ichild[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; } /***************************************************************************** -- 2.34.1