--- ray/src/hd/rholo3.c 1997/11/04 11:52:21 3.4 +++ ray/src/hd/rholo3.c 1997/11/21 17:47:56 3.9 @@ -116,19 +116,26 @@ int nents; default: error(CONSISTENCY, "bundle_set called with unknown operation"); } - n = 0; /* allocate packet holder */ - for (i = 0; i < nents; i++) - if (clist[i].nr > n) - n = clist[i].nr; - p = (PACKHEAD *)malloc(sizeof(PACKHEAD) + n*sizeof(RAYVAL)); + if (outdev == NULL) + return; + n = 8*RPACKSIZ; /* allocate packet holder */ + p = (PACKHEAD *)malloc(packsiz(n)); if (p == NULL) goto memerr; /* display what we have */ for (i = 0; i < nents; i++) if ((b = hdgetbeam(hdlist[clist[i].hd], clist[i].bi)) != NULL) { - bcopy((char *)hdbray(b), (char *)(p+1), + if (b->nrm > n) { + n = b->nrm; + p = (PACKHEAD *)realloc((char *)p, packsiz(n)); + if (p == NULL) + goto memerr; + } + bcopy((char *)hdbray(b), (char *)packra(p), (p->nr=b->nrm)*sizeof(RAYVAL)); - disp_packet((PACKET *)p); + p->hd = clist[i].hd; + p->bi = clist[i].bi; + disp_packet(p); } free((char *)p); /* clean up */ return; @@ -272,7 +279,7 @@ sortcomplist() /* fix our list order */ done_packets(flush_queue()); if (complen <= 0) /* check to see if there is even a list */ return; - if (lastin < 0) /* flag to sort entire list */ + if (lastin < 0 || listpos*4 >= complen*3) qsort((char *)complist, complen, sizeof(PACKHEAD), beamcmp); else if (listpos) { /* else sort and merge sublist */ list2 = (PACKHEAD *)malloc(listpos*sizeof(PACKHEAD));