Branch: Tag:

2013-02-07

2013-02-07 12:52:19 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Fixed padding bug in string_builder_append_integer().

The support for left padding was broken, and would always
add the full padding string.

eg string_builder_append_integer(&s, 16, 10, APPEND_LEFT|APPEND_SIGNED, 2, 0)
would append the string "16 " instead of the expected "16".

This bug also affected string_builder_sprintf().

2732:       tmp = val;    if (base & (base - 1)) { +  size_t cnt;    /* Calculate the output length.    * Use do-while to ensure that zero isn't output as an empty string.    */
2753:    min_width = 0;    }    +  cnt = len; +     tmp = val;    switch(s->s->size_shift) {    case 0:    {    p_wchar0 *p = string_builder_allocate(s, len, 0);    do { -  p[--len] = numbers[tmp%base]; +  p[--cnt] = numbers[tmp%base];    tmp /= base; -  } while (len); +  } while (cnt);    }    break;    case 1:    {    p_wchar1 *p = string_builder_allocate(s, len, 0);    do { -  p[--len] = numbers[tmp%base]; +  p[--cnt] = numbers[tmp%base];    tmp /= base; -  } while (len); +  } while (cnt);    }    break;    case 2:    {    p_wchar2 *p = string_builder_allocate(s, len, 0);    do { -  p[--len] = numbers[tmp%base]; +  p[--cnt] = numbers[tmp%base];    tmp /= base; -  } while (len); +  } while (cnt);    }    break;    }