Ticket 173: bug in OSSP str_format.c %x handling?
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) {
Remarks:
Properties:
  | Type: | code |  | Version: | str-0.9.12.tar.gz | 
  | Status: | new |  | Created: | 2009-Jun-15 13:31 | 
  | Severity: | 3 |  | Last Change: | 2009-Jun-15 13:31 | 
  | Priority: | 3 |  | Subsystem: | str | 
  | Assigned To: | rse |  | Derived From: |  | 
  | Creator: | anonymous |