When porting the new mkisofs (from cdr-tools-2.0) to neutrino, I found
a wierd behaviour of the qsort() function:
Sometimes it calls the compare function with both pointers beeing
identical, which is pretty senseless. I also couldn’t reproduce this
on other platforms (QNX4, Linux), so I’d like to call it a bug .
Any comments?
Here’s a sample C file, that illustrates the problem:
The larger you choose ARRAY_SIZE, the mort “Identical pointers!” youe
get.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef ARRAY_SIZE
#define ARRAY_SIZE 33
#endif
int compare ( const void* l, const void* r )
{
const char** ll = (const char**) l;
const char** rr = (const char**) r;
if ( l == r )
{
printf(“Identical pointers!\n”);
return 0;
}
return strcmp ( *ll, rr );
}
int main ( int argc, char argv[] )
{
const int n = ARRAY_SIZE;
char* array[ARRAY_SIZE];
int i;
printf("------------------------ Original\n");
for ( i = 0; i < n; i++)
{
array [ i ] = strdup ( tmpnam ( NULL ) );
printf ( “%s\n”, array_);
}
printf( “------------------------ Sortieren\n”);
qsort ( array, n, sizeof(char * ), compare );
printf( “------------------------ Sortiert!\n”);
for ( i = 0; i < n; i++)
{
printf ( “%s\n”, array);
}
return 0;
}
\
| / | __ ) | Karsten.Hoffmann@mbs-software.de MBS-GmbH
| |/| | _ _ \ Phone : +49-2151-7294-38 Karsten Hoffmann
| | | | |) |__) | Fax : +49-2151-7294-50 Roemerstrasse 15
|| ||// Mobile: +49-172-3812373 D-47809 Krefeld_