SourceForge has been redesigned. Learn more.
Close

#343 Patch to fix incorrect operation in x_sprintf

closed-fixed
nobody
2007-10-03
2007-09-05
No

mingwex/gdtoa/mingw_snprintf.c

When x_sprintf is called with an l (ell) parameter in the format string, such as %ld, it incorrectly assumes that the matching argument will be long long (as if I specified %lld [ell ell dee]).

This is due to a bug in this part of the file:

case 'l':
if (fmt[0] == 'l')
{
fmt++;
len = LEN_LL;
}
else
len = LEN_LL;
goto fmtloop;

The second LEN_LL should read LEN_L.

The attached patch fixes the problem.

See:
http://sourceforge.net/mailarchive/forum.php?thread_name=1188956327.14619.10.camel%40devit.rsaisp.com&forum_name=mingw-users
For more information

Discussion

  • David Daeschler

    David Daeschler - 2007-09-06

    Logged In: YES
    user_id=1043271
    Originator: YES

    I've made the changes to mingwex/gdtoa/mingw_snprintf.c to allow %hh to work correctly. I followed the formatting, flow, and style of code that I saw in mingw_snprintf.c. I also found a few other bugs in the code when I was in there.

    2007-09-06 David C. Daeschler <daveregs@rsaisp.com>
    * mingw_sprintf.c (x_sprintf):
    l (ell) length specifier being treated as ll (ell ell) in all cases

    hh was not recognized:
    (hh Specifies that a following d, i, o, u, x, or X conversion
    specifier applies to a signed char or unsigned char argument (the
    argument will have been promoted according to the integer
    promotions, but its value shall be converted to signed char or
    unsigned char before printing); or that a following n conversion
    specifier applies to a pointer to a signed char argument.)

    fix bug in output of characters written to a short when using %hn
    (switch/case fallthrough, the LEN_S case was falling through to
    the LEN_LL case which would cause corruption)

     
  • David Daeschler

    David Daeschler - 2007-09-06

    Patch to mingwex/gdtoa/mingw_snprintf.c

     
  • David Daeschler

    David Daeschler - 2007-09-06

    Logged In: YES
    user_id=1043271
    Originator: YES

    File Added: mingw_runtime.diff

     
  • Danny Smith

    Danny Smith - 2007-09-23

    Logged In: YES
    user_id=11494
    Originator: NO

    I've committed these hunks as obvious bug fixes.

    2007-09-24 David C. Daeschler <daveregs@rsaisp.com>

    \* mingwex/gdtoa/mingw\_snprintf.c \(x\_sprintf\): Correct LEN\_L typo in 'l'
    case.  Add missing break in 's'/LEN\_S case.
    

    Index: mingw_snprintf.c

    RCS file: /cvs/src/src/winsup/mingw/mingwex/gdtoa/mingw_snprintf.c,v
    retrieving revision 1.2
    diff -c -3 -p -r1.2 mingw_snprintf.c
    *** mingw_snprintf.c 25 Aug 2007 13:49:37 -0000 1.2
    --- mingw_snprintf.c 23 Sep 2007 22:04:43 -0000
    *************** x_sprintf
    *** 465,471 ****
    len = LEN_LL;
    }
    else
    ! len = LEN_LL;
    goto fmtloop;
    case 'L':
    flag_ld++;
    --- 465,471 ----
    len = LEN_LL;
    }
    else
    ! len = LEN_L;
    goto fmtloop;
    case 'L':
    flag_ld++;
    *************** x_sprintf
    *** 617,622 ****
    --- 617,623 ----
    break;
    case LEN_S:
    *(short*)ip = c;
    + break;
    case LEN_LL:
    *(long long*) ip = c;
    break;

     
  • Chris Sutcliffe

    Chris Sutcliffe - 2007-10-03
    • status: open --> closed-fixed