From 49dbdd4940aa78021f4ba516f4edb632058262bf Mon Sep 17 00:00:00 2001 From: Samo Penic <samo.penic@fe.uni-lj.si> Date: Wed, 25 Jun 2014 09:44:48 +0000 Subject: [PATCH] Fixes bugs in creating IsakPrograms compatible image --- src/coord.c | 29 ++++++++++++++++------------- 1 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/coord.c b/src/coord.c index a5723a8..afcc50d 100644 --- a/src/coord.c +++ b/src/coord.c @@ -1,5 +1,5 @@ #include<general.h> - +#include<stdlib.h> ts_coord_list *init_coord_list(){ @@ -10,29 +10,32 @@ return coordlist; } -ts_coord_list add_coord(ts_coord_list *coordlist, ts_double e1, ts_double e2, ts_double e3, ts_uint coord_type){ +ts_bool add_coord(ts_coord_list *coordlist, ts_double e1, ts_double e2, ts_double e3, ts_uint coord_type){ - coordlist->N++; - coordlist->coord=(ts_coord *)realloc(coordlist->coord,N*sizeof(ts_coord)); + coordlist->coord=(ts_coord **)realloc(coordlist->coord,(coordlist->n+1)*sizeof(ts_coord *)); if(coordlist->coord==NULL){ fatal("Cannot allocate memory for coord in coordlist",998); } + + + coordlist->coord[coordlist->n]=(ts_coord *)calloc(1, sizeof(ts_coord)); - coordlist->coord[coordlist->N-1]->e1=e1; - coordlist->coord[coordlist->N-1]->e2=e2; - coordlist->coord[coordlist->N-1]->e3=e3; - coordlist->coord[coordlist->N-1]->coord_type=coord_type; - + coordlist->coord[coordlist->n]->e1=e1; + coordlist->coord[coordlist->n]->e2=e2; + coordlist->coord[coordlist->n]->e3=e3; + coordlist->coord[coordlist->n]->coord_type=coord_type; + coordlist->n++; + return TS_SUCCESS; } -ts_bool coord_list_free(ts_coord_list coordlist){ +ts_bool coord_list_free(ts_coord_list *coordlist){ ts_uint i; if(coordlist==NULL) return TS_SUCCESS; - for(i=0; i<coordlist->N;i++){ - if(coordlist->coord[N]!=NULL) free(coordlist->coord[N]); + for(i=0; i<coordlist->n;i++){ + if(coordlist->coord[i]!=NULL) free(coordlist->coord[i]); } - + free(coordlist->coord); free(coordlist); return TS_SUCCESS; -- Gitblit v1.9.3