[issue35560] format(float(123), "00") causes segfault in debug builds

Karthikeyan Singaravelan report at bugs.python.org
Sat Dec 22 09:42:21 EST 2018


Karthikeyan Singaravelan <tir.karthi at gmail.com> added the comment:

Looking into the code min_width is returned as -2 and hence the assert fails. spec->n_min_width is passed as min_width to _PyUnicode_InsertThousandsGrouping that is used in the assert statement and I came across below comment that min_width can go negative and it's okay. So is the assert statement validating for it to be always greater than or equal to zero not needed?

https://github.com/python/cpython/blob/59423e3ddd736387cef8f7632c71954c1859bed0/Python/formatter_unicode.c#L529

    /* min_width can go negative, that's okay. format->width == -1 means
       we don't care. */
    if (format->fill_char == '0' && format->align == '=')
        spec->n_min_width = format->width - n_non_digit_non_padding;
    else
        spec->n_min_width = 0;

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35560>
_______________________________________


More information about the Python-bugs-list mailing list