1- /* Copyright (c) 2000, 2010 , Oracle and/or its affiliates. All rights reserved.
1+ /* Copyright (c) 2000, 2015 , Oracle and/or its affiliates. All rights reserved.
22
33 This program is free software; you can redistribute it and/or modify
44 it under the terms of the GNU General Public License as published by
@@ -41,6 +41,16 @@ static int native_compare(size_t *length, unsigned char **a, unsigned char **b)
4141
4242#else /* __sun */
4343
44+ /**
45+ Special case for ORDER BY / GROUP BY CHAR(0) NOT NULL
46+ */
47+ static
48+ int ptr_compare_zero_length (size_t * compare_length __attribute__((unused )),
49+ uchar * * a __attribute__((unused )),
50+ uchar * * b __attribute__((unused )))
51+ {
52+ return 0 ;
53+ }
4454static int ptr_compare (size_t * compare_length , uchar * * a , uchar * * b );
4555static int ptr_compare_0 (size_t * compare_length , uchar * * a , uchar * * b );
4656static int ptr_compare_1 (size_t * compare_length , uchar * * a , uchar * * b );
@@ -58,6 +68,8 @@ qsort2_cmp get_ptr_compare (size_t size __attribute__((unused)))
5868#else
5969qsort2_cmp get_ptr_compare (size_t size )
6070{
71+ if (size == 0 )
72+ return (qsort2_cmp ) ptr_compare_zero_length ;
6173 if (size < 4 )
6274 return (qsort2_cmp ) ptr_compare ;
6375 switch (size & 3 ) {
@@ -85,6 +97,7 @@ static int ptr_compare(size_t *compare_length, uchar **a, uchar **b)
8597 reg3 int length = * compare_length ;
8698 reg1 uchar * first ,* last ;
8799
100+ DBUG_ASSERT (length > 0 );
88101 first = * a ; last = * b ;
89102 while (-- length )
90103 {
0 commit comments