[net.sources.bugs] bugs in sort

craig@hp-pcd.UUCP (craig) (09/04/86)

The is a bug with the SORT program posted to net.sources.

Bug #1
In the routine merge(nfiles) is a line:
	memcpy(Heap,Heap+1,nfile*sizeof(HEAP));
this should be:
	memcpy((char *)Heap, (char *)(Heap+1), nfiles*sizeof(*Heap));
Or if you don't have memcpy or are worried about overlapping memory moves:
	{
 	  int j;
	  for (j=0; j<nfiles; j++) Heap[j] = Heap[j+1];
	}


Bug #2
If you sort a file with 1024 lines in it (such as one of the temp files (eg
merge.1)) sort will not output anything.
In the routine main(argc,argv):
add another int var:  eg int n=0;
add as the first statement of the do loop (do{) to do{ n++;
then change if (numpasses>1) to if (n>1)