Skip to content
Snippets Groups Projects
Commit 4a5d8262 authored by Stephan Bosch's avatar Stephan Bosch
Browse files

Fixed extremely stupid bug in the i;ascii-numeric comparator.

parent d3d97752
No related branches found
No related tags found
No related merge requests found
...@@ -97,6 +97,7 @@ static int cmp_i_ascii_numeric_compare ...@@ -97,6 +97,7 @@ static int cmp_i_ascii_numeric_compare
const char *kend = key + key_size; const char *kend = key + key_size;
const char *vp = val; const char *vp = val;
const char *kp = key; const char *kp = key;
int digits, i;
/* Ignore leading zeros */ /* Ignore leading zeros */
...@@ -106,25 +107,41 @@ static int cmp_i_ascii_numeric_compare ...@@ -106,25 +107,41 @@ static int cmp_i_ascii_numeric_compare
while ( *kp == '0' && kp < kend ) while ( *kp == '0' && kp < kend )
kp++; kp++;
while ( vp < vend && kp < kend ) { /* Check whether both numbers are equally long in terms of digits */
if ( !i_isdigit(*vp) || !i_isdigit(*kp) )
break;
if ( *vp != *kp )
break;
digits = 0;
while ( vp < vend && kp < kend && i_isdigit(*vp) && i_isdigit(*kp) ) {
vp++; vp++;
kp++; kp++;
digits++;
} }
if ( vp == vend || !i_isdigit(*vp) ) { if ( vp == vend || !i_isdigit(*vp) ) {
if ( kp == kend || !i_isdigit(*kp) ) if ( kp != kend && i_isdigit(*kp) ) {
return 0; /* Value is less */
else
return -1; return -1;
} else if ( kp == kend || !i_isdigit(*kp) ) }
} else {
/* Value is greater */
return 1; return 1;
}
/* Equally long: compare digits */
vp -= digits;
kp -= digits;
i = 0;
while ( i < digits ) {
if ( *vp > *kp )
return 1;
else if ( *vp < *kp )
return -1;
kp++;
vp++;
i++;
}
return (*vp > *kp); return 0;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment

Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.