[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#279044: marked as done (libc6: qsort() doesn't sort for large size)



Your message dated Sun, 31 Oct 2004 12:05:39 -0500
with message-id <1099242339.1418.248.camel@parity.ne.client2.attbi.com>
and subject line Bug#279044: libc6: qsort() doesn't sort for large size
has caused the attached Bug report to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what I am
talking about this indicates a serious mail system misconfiguration
somewhere.  Please contact me immediately.)

Debian bug tracking system administrator
(administrator, Debian Bugs database)

--------------------------------------
Received: (at submit) by bugs.debian.org; 31 Oct 2004 08:37:01 +0000
>From Thomas.Koenig@online.de Sun Oct 31 01:37:01 2004
Return-path: <Thomas.Koenig@online.de>
Received: from moutng.kundenserver.de [212.227.126.190] 
	by spohr.debian.org with esmtp (Exim 3.35 1 (Debian))
	id 1COBCv-0001p1-00; Sun, 31 Oct 2004 01:37:01 -0700
Received: from [212.227.126.207] (helo=mrelayng.kundenserver.de)
	by moutng.kundenserver.de with esmtp (Exim 3.35 #1)
	id 1COBAy-0007aR-00
	for submit@bugs.debian.org; Sun, 31 Oct 2004 09:35:00 +0100
Received: from [80.141.205.17] (helo=meiner.onlinehome.de)
	by mrelayng.kundenserver.de with asmtp (Exim 3.35 #1)
	id 1COBAx-0001CM-00; Sun, 31 Oct 2004 09:34:59 +0100
Received: from ig25 by meiner.onlinehome.de with local (Exim 3.36 #1 (Debian))
	id 1COC75-0001NU-00; Sun, 31 Oct 2004 10:35:03 +0100
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
From: Thomas Koenig <Thomas.Koenig@online.de>
To: Debian Bug Tracking System <submit@bugs.debian.org>
Subject: libc6: qsort() doesn't sort for large size
X-Mailer: reportbug 3.1
Date: Sun, 31 Oct 2004 10:35:02 +0100
Message-Id: <[🔎] E1COC75-0001NU-00@meiner.onlinehome.de>
Sender: Thomas Koenig <Thomas.Koenig@online.de>
X-Provags-ID: kundenserver.de abuse@kundenserver.de auth:82006718d44785d1b0aefbb6e084916e
Delivered-To: submit@bugs.debian.org
X-Spam-Checker-Version: SpamAssassin 2.60-bugs.debian.org_2004_03_25 
	(1.212-2003-09-23-exp) on spohr.debian.org
X-Spam-Status: No, hits=-8.0 required=4.0 tests=BAYES_00,HAS_PACKAGE 
	autolearn=no version=2.60-bugs.debian.org_2004_03_25
X-Spam-Level: 

Package: libc6
Version: 2.3.2.ds1-18
Severity: normal

$ cat mysort.c
#include <stdio.h>
#include <stdlib.h>

#define DATASIZE 1800
#define NDAT 100000
typedef struct {
    int key;
    char data [DATASIZE];
} mydata;

int mycomp(void const *p1, void const *p2) {
    mydata const *v1, *v2;
    v1 = p1;
    v2 = p2;
    return (v1->key) < (v2->key);
}

int main() {
    int i;
    mydata *p;

    p = calloc(NDAT, sizeof(mydata));
    for (i=0; i<NDAT; i++) {
        p[i].key = random();
    }
    qsort(p, NDAT, sizeof(*p), mycomp);
    for (i=0; i<10; i++) {
        printf("%d\n",p[i].key);
    }
    return 0;
}
$ gcc -g -Wall -o mysort mysort.c
$ ./mysort
1804289383
585681566
200863687
1979603839
2085853640
1489258466
556712446
1788149182
1893664349
43517041

which is pretty unsorted, if you ask me :-)

It's OK for a smaller struct, though:

$ cat mysort-works.c
#include <stdio.h>
#include <stdlib.h>

#define DATASIZE 20
#define NDAT 100000
typedef struct {
    int key;
    char data [DATASIZE];
} mydata;

int mycomp(void const *p1, void const *p2) {
    mydata const *v1, *v2;
    v1 = p1;
    v2 = p2;
    return (v1->key) < (v2->key);
}

int main() {
    int i;
    mydata *p;

    p = calloc(NDAT, sizeof(mydata));
    for (i=0; i<NDAT; i++) {
        p[i].key = random();
    }
    qsort(p, NDAT, sizeof(*p), mycomp);
    for (i=0; i<10; i++) {
        printf("%d\n",p[i].key);
    }
    return 0;
}
$ gcc -g -Wall -o mysort-works mysort-works.c
$ ./mysort-works
2147469841
2147466242
2147414141
2147378031
2147317028
2147316088
2147311484
2147278491
2147248040
2147230544
$

-- System Information:
Debian Release: 3.1
  APT prefers unstable
  APT policy: (500, 'unstable'), (1, 'experimental')
Architecture: i386 (i686)
Kernel: Linux 2.6.8-1-k7
Locale: LANG=C, LC_CTYPE=de_DE@euro (charmap=ISO-8859-15)

Versions of packages libc6 depends on:
ii  libdb1-compat                 2.1.3-7    The Berkeley database routines [gl

-- no debconf information

---------------------------------------
Received: (at 279044-done) by bugs.debian.org; 31 Oct 2004 17:06:11 +0000
>From jwnimmer@alum.mit.edu Sun Oct 31 09:06:11 2004
Return-path: <jwnimmer@alum.mit.edu>
Received: from rwcrmhc11.comcast.net [204.127.198.35] 
	by spohr.debian.org with esmtp (Exim 3.35 1 (Debian))
	id 1COJ9f-0003Oy-00; Sun, 31 Oct 2004 09:06:11 -0800
Received: from parity.ne.client1.attbi.com (parity.ne.client2.attbi.com[24.128.51.141](misconfigured sender))
          by comcast.net (rwcrmhc11) with ESMTP
          id <2004103117054001300bqfbie>; Sun, 31 Oct 2004 17:05:40 +0000
Received: from localhost ([127.0.0.1])
	by parity.ne.client1.attbi.com with esmtp (Exim 3.36 #1 (Debian))
	id 1COJ99-0007v8-00
	for <279044-done@bugs.debian.org>; Sun, 31 Oct 2004 12:05:39 -0500
Subject: Re: Bug#279044: libc6: qsort() doesn't sort for large size
From: Jeremy Nimmer <jwnimmer@alum.mit.edu>
To: 279044-done@bugs.debian.org
In-Reply-To: <[🔎] E1COC75-0001NU-00@meiner.onlinehome.de>
References: <[🔎] E1COC75-0001NU-00@meiner.onlinehome.de>
Content-Type: text/plain
Message-Id: <1099242339.1418.248.camel@parity.ne.client2.attbi.com>
Mime-Version: 1.0
X-Mailer: Ximian Evolution 1.4.6 
Date: Sun, 31 Oct 2004 12:05:39 -0500
Content-Transfer-Encoding: 7bit
Delivered-To: 279044-done@bugs.debian.org
X-Spam-Checker-Version: SpamAssassin 2.60-bugs.debian.org_2004_03_25 
	(1.212-2003-09-23-exp) on spohr.debian.org
X-Spam-Status: No, hits=-6.0 required=4.0 tests=BAYES_00,HAS_BUG_NUMBER 
	autolearn=no version=2.60-bugs.debian.org_2004_03_25
X-Spam-Level: 

Thomas,

In general, it's unlikely that anything you think is a libc bug is
really a libc bug, especially for something like a severe functional
problem like "qsort() doesn't sort".

In this case, it's your bug:

On Sun, 2004-10-31 at 04:35, Thomas Koenig wrote:
> int mycomp(void const *p1, void const *p2) {
>     mydata const *v1, *v2;
>     v1 = p1;
>     v2 = p2;
>     return (v1->key) < (v2->key);
> }

The above is an incorrect comparison routine.  Did you read the qsort
man page?  Is says, in part:

        The comparison function must return an integer less than, equal
        to, or greater than zero if the first argument is considered to
        be respectively less than, equal to, or greater than the second.

So using "<" is totally wrong.  I'd suggest "(v1->key) - (v2->key)" if
you want ascending order.

Thanks,
- Jeremy

p.s. I'm not a debian developer; I'm just trying to save their time for
the real problems.




Reply to: