Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 15 Sep 2002 21:42:53 -0700 (PDT)
From:      Jin Guojun (DSD staff) <jin@pesto.lbl.gov>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   kern/42818: qsort can only sort up to 6 element for structure
Message-ID:  <200209160442.g8G4gr5p012462@pesto.lbl.gov>

next in thread | raw e-mail | index | archive | help


>Number:         42818
>Category:       kern
>Synopsis:       qsort can only sort up to 6 element for structure
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Sep 15 21:50:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Jin Guojun (DSD staff)
>Release:        FreeBSD 4.6.2-RELEASE i386
>Organization:
>Environment:


	FreeBSD 4.x

>Description:
	The code included in "How-To-Repeat" section works on Linux, Solaris,
	but fails on FreeBSD when array size is greater than 6.

solaris/linux:
./qsort-app
orig:   2  3  0  1  4  5  6  7  8  9 22 23 45 56 10 11
sort:   0  1  2  3  4  5  6  7  8  9 10 11 22 23 45 56  OK 

orig:   0  1  2  3  4  5  6  7  8  9 10 11 22 23
sort:   0  1  2  3  4  5  6  7  8  9 10 11 22 23        OK 

orig:   0  1  2  3  4  5  6  7  8  9
sort:   0  1  2  3  4  5  6  7  8  9    OK 

orig:   2  3  0  1  4  5  6  7  8  9 12 13
sort:   0  1  2  3  4  5  6  7  8  9 12 13      OK 

orig:   0  1  2  3  4  5  6  7  8  9 12 13 15 16 10 11
sort:   0  1  2  3  4  5  6  7  8  9 10 11 12 13 15 16  OK 


FreeBSD:
orig:   2  3  0  1  4  5  6  7  8  9 22 23 45 56 10 11
sort:  10 11  0  1  4  5  6  7  8  9  2  3 22 23 45 56  FAILED 

orig:  10 11  0  1  4  5  6  7  8  9  2  3 22 23
sort:   6  7  0  1  4  5  2  3  8  9 10 11 22 23        FAILED 

orig:   6  7  0  1  4  5  2  3  8  9
sort:   0  1  2  3  4  5  6  7  8  9    OK 

orig:   2  3  0  1  4  5  6  7  8  9 12 13
sort:   0  1  2  3  4  5  6  7  8  9 12 13      OK 

orig:   0  1  2  3  4  5  6  7  8  9 12 13 15 16 10 11
sort:  10 11  2  3  4  5  6  7  8  9  0  1 12 13 15 16  FAILED 


>How-To-Repeat:

	make qsort-app
	./qsort-app

% cat qsort-app.c

#include <stdlib.h>

smaller(const void *i1, const void *i2)
{
return  *(int*)i1 > *(int*)i2;
}

#define	N	8

typedef	int	ia_t[2];

main()
{
int	i;
ia_t	d0[N] = {2, 3, 0, 1, 4, 5, 6, 7, 8, 9, 22, 23, 45, 56, 10, 11},
	d1[N] = {2, 3, 0, 1, 4, 5, 6, 7, 8, 9, 12, 13, 15, 16, 10, 11};

#define	test(dx, n)	{	\
	ia_t	*da = dx;	\
	printf("orig: ");	\
	for (i=0; i<n; i++)	\
		printf("%3d %2d", da[i][0], da[i][1]);	\
	qsort(da, n, sizeof(da[0]), smaller);	\
	printf("\nsort: ");	\
	for (i=0; i<n; i++)	\
		printf("%3d %2d", da[i][0], da[i][1]);	\
	printf("	%s \n\n", da[0][0] == 0 ? "OK" : "FAILED");	\
    }

	test(d0, N);
	test(d0, 7);
	test(d0, 5);
	test(d1, 6);
	test(d1, N);
}

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200209160442.g8G4gr5p012462>