https://bugzilla.wikimedia.org/show_bug.cgi?id=69249

Kevin Israel (PleaseStand) <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |[email protected],
                   |                            |[email protected]

--- Comment #4 from Kevin Israel (PleaseStand) <[email protected]> ---
I think this is a case where gmp_init() is not behaving as documented on
php.net. ltrim( $input, '0' ) should suffice as a workaround.

The documentation:

The base may vary from 2 to 36. If base is 0 (default value), the actual base
is determined from the leading characters: if the first two characters are 0x
or 0X, hexadecimal is assumed, otherwise if the first character is "0", octal
is assumed, otherwise decimal is assumed.

[It doesn't say "if and only if", though there is no mention of autodetection
when base is not 0.]

PHP 5.6, from convert_to_gmp() in ext/gmp/gmp.c:

if (Z_STRLEN_P(val) > 2) {
    if (numstr[0] == '0') {
        if (numstr[1] == 'x' || numstr[1] == 'X') {
            base = 16;
            skip_lead = 1;
        } else if (base != 16 && (numstr[1] == 'b' || numstr[1] == 'B')) {
            base = 2;
            skip_lead = 1;
        }
    }
}

[Why is this code even present when simply leaving it out, according to the GMP
documentation
<https://gmplib.org/manual/Assigning-Integers.html#Assigning-Integers>, would
produce the documented behavior?]

HHVM, from variantToGMPData():

//Figure out what Base to use based on the ~*data*~
if (strLength > 1 && dataString[0] == '0') {
  if (strLength > 2) {
    if (dataString[1] == 'x' || dataString[1] == 'X') {
      base = 16;
      dataString = dataString.substr(2);
    } else if (base < 12 && (dataString[1] == 'b'
                             || dataString[1] == 'B')) {
      base = 2;
      dataString = dataString.substr(2);
    }
  }
  if (base == -1) {
    base = 8;
  }
} else if (strLength == 0) {
  dataString = s_gmp_0.get();
}

if (base == -1) {
  base = GMP_DEFAULT_BASE;
}

[Also note the use of -1 rather than 0 for autodetect.]

-- 
You are receiving this mail because:
You are the assignee for the bug.
You are on the CC list for the bug.
_______________________________________________
Wikibugs-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikibugs-l

Reply via email to