Mantis - Quercus
Viewing Issue Advanced Details
2271 minor always 12-21-07 07:25 02-05-08 12:39
jang  
nam  
normal  
closed 3.1.3  
fixed  
none    
none 3.1.5  
0002271: thinko in base_convert: doesn't always work for large bases
There's a bug in MathModule#base_convert - two, actually. The first is the conversion of the input value to a long result:

     if ('0' <= ch && ch <= '9')
        value = ch - '0';
      else if ('a' <= ch && ch <= 'z')
        value = ch - 'a' + 10;
      else if ('A' <= ch && ch <= 'Z')
        value = ch - 'a' + 10;

Pretty sure that last line should be, er,

        value = ch - 'A' + 26;

(which 'a' - 10 doesn't evaluate to).

On output, something similar:

      if (d < 10)
        sb.append((char) (d + '0'));
      else
        sb.append((char) (d - 10 + 'a'));

is also erroneous. Additional information is a sample piece of code that demonstrates this: it'll spew out nonprintable characters occasionally.

Caught this whilst hacking on Elgg to make it run under quercus; as it is, the piece of Elgg code that does this is pretty broken too :-/ but figured you'd probably want the fix anyway.

Cheers,
jan
<?php
        $s = md5(time() . "123");
        echo $s;
        echo "\n";
        echo base_convert($s, 16, 36);
?>

Notes
(0002721)
nam   
02-05-08 12:39   
php/1328
php/1329