~nabijaczleweli/ossp#173: 
[str 0.9.12] bug in OSSP str_format.c %x handling?

#Upstream Ticket 173 from 2009-06-15 13:31:55

One of my colleagues found that %x sometimes doesn't output the '0x', particularily "%d : %x", a, b doesn't print the 0x when a == 0.

It appears this code could be at fault:

            /* Unsigned Hexadecimal Integer */
            case 'x':
            case 'X':
                if (var_type == IS_QUAD) {
                    ui_quad = va_arg(ap, u_quad_int);
                    s = conv_p2_quad(ui_quad, 4, *fmt,
                                     &num_buf[NUM_BUF_SIZE], &s_len);
                }
                else {
                    if (var_type == IS_LONG)
                        ui_num = (u_long_int)va_arg(ap, u_long_int);
                    else if (var_type == IS_SHORT)
                        ui_num = (u_long_int)(unsigned short)va_arg(ap, unsigned int);
                    else
                        ui_num = (u_long_int)va_arg(ap, unsigned int);
                    s = conv_p2(ui_num, 4, *fmt, &num_buf[NUM_BUF_SIZE], &s_len);
                }
                FIX_PRECISION(adjust_precision, precision, s, s_len);
                if (alternate_form && i_num != 0) {
                    *--s = *fmt; /* 'x' or 'X' */
                    *--s = '0';
                    s_len += 2;
                }
                break;

I think the:

                if (alternate_form && i_num != 0) {

should be:

                if (alternate_form && ui_num != 0) {
Status
REPORTED
Submitter
~nabijaczleweli
Assigned to
No-one
Submitted
4 months ago
Updated
4 months ago
Labels
CVSTrac str