From 9a6a54586af6227c72382e039449bcf768b98344 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ji=C5=99=C3=AD=20Filipovi=C4=8D?= Date: Thu, 15 Mar 2007 13:01:50 +0000 Subject: [PATCH] fix the bug in merging attributes --- org.glite.jp.primary/src/attrs.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/org.glite.jp.primary/src/attrs.c b/org.glite.jp.primary/src/attrs.c index d2f5a1d..5c1873a 100644 --- a/org.glite.jp.primary/src/attrs.c +++ b/org.glite.jp.primary/src/attrs.c @@ -68,6 +68,7 @@ static int merge_attrvals(glite_jp_attrval_t **out,int nout,const glite_jp_attrv for (nin=0; in[nin].name; nin++); *out = realloc(*out,(nout+nin+1) * sizeof **out); memcpy(*out + nout,in,(nin+1) * sizeof **out); + memset(*out + nout+nin, 0, sizeof **out); return nout+nin; } @@ -104,7 +105,7 @@ void process_files(glite_jp_context_t ctx, const char *job, glite_jp_attrval_t** glite_jpps_get_attrs(glite_jp_context_t ctx,const char *job,char **attr,int nattr,glite_jp_attrval_t **attrs_out) { - glite_jp_attrval_t *meta = NULL,*out = NULL,*tag_out; + glite_jp_attrval_t *meta = NULL,*out = NULL,*tag_out = NULL; char const **other = NULL; int i,j,nmeta,nother,err = 0,nout = 0; @@ -138,10 +139,7 @@ glite_jpps_get_attrs(glite_jp_context_t ctx,const char *job,char **attr,int natt void* beh; for (i = 0; i < nother; i++){ if (! glite_jppsbe_read_tag(ctx, job, other[i], &tag_out)) { - for (j=0; tag_out[j].name; j++); - out = realloc(out,(nout+j) * sizeof *out); - memcpy(out+nout,tag_out,j * sizeof *out); - nout += j; + nout = merge_attrvals(&out, nout, tag_out); free(tag_out); tag_out = NULL; } for (j = 0; known_namespaces[j].namespace; j++) { -- 1.8.2.3