[Python-Dev] buglet in long("123\0", 10)

Nick Coghlan ncoghlan at gmail.com
Sun Jan 14 08:06:45 CET 2007


Guido van Rossum wrote:
>>> long('123\0', 10)
> 123L

Interesting - long_new goes through PyNumber_Long if no explicit base is 
provided. That does a pre-check for embedded NULLs in the input string. 
With an explicit base, however, PyLong_FromString is called directly. 
Since that API takes a char* string, it stops at the first embedded NULL:

 >>> long('123\0003', 10)
123L
 >>> long('123\00032', 10)
123L


So 'long_from_string' in abstract.c already has this problem solved - 
the helper function just needs to be moved into longobject.c so it can 
be used for explicit bases as well.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-Dev mailing list