From: Aleš Křenek Date: Fri, 15 Jul 2005 11:12:12 +0000 (+0000) Subject: better glite_jp_attr_union() X-Git-Tag: glite-lb-ws-interface_R_2_0_0~6 X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=9f1775334a8b9970841aa825c4c3d9383e25df52;p=jra1mw.git better glite_jp_attr_union() --- diff --git a/org.glite.jp.common/src/attr.c b/org.glite.jp.common/src/attr.c index 7599a63..3dfa1cd 100644 --- a/org.glite.jp.common/src/attr.c +++ b/org.glite.jp.common/src/attr.c @@ -43,19 +43,27 @@ void glite_jp_attr_union(const glite_jp_attr_t *a, const glite_jp_attr_t *b, int ac,bc,c,i,j; glite_jp_attr_t *res; - assert(a); assert(b); assert(out); - for (ac=0; a[ac].type; ac++); - for (bc=0; b[bc].type; bc++); + assert(out); + if (a) for (ac=0; a[ac].type; ac++); else ac=0; + if (b) for (bc=0; b[bc].type; bc++); else bc=0; + + if ((c = ac+bc) == 0) { + *out = NULL; + return; + } + res = malloc((ac+bc+1) * sizeof *res); memcpy(res,a,ac * sizeof *a); memcpy(res+ac,b,bc * sizeof *b); memset(res+ac+bc,0,sizeof *res); - c = ac+bc; qsort(res,c,sizeof *res,attr_cmp); for (i=0; i i+1) memmove(res+i+1,res+j,c-j); + if (j > i+1) { + memmove(res+i+1,res+j,c-j); + c -= j - (i+1); + } } for (i=0; res[i].type; i++) switch (res[i].type) {