Menu

#1945 incorrect unsigned 32-bit integer truncation

closed-duplicate
Front-end
5
2015-06-17
2012-02-21
Woody
No

I am using an open source md5 c code. There are following defines:
#define F(x, y, z) ((((y) ^ (z)) & (x)) ^ (z))
#define ROTATE_LEFT(x, n) rlc_32x8((x), (n))
#define FF(a, b, c, d, x, s, ac) \
{(a) += F ((b), (c), (d)) + (x) + (ULONG)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
Where ULONG is unsigned 32-bit integer. (#define ULONG unsigned long)
It compiled ok with 3.0.0, but get "md5.c:313: warning 184: integer constant '3614090360' out of range, truncated to
2147483647." now.

Version used:
SDCC : mcs51/gbz80/z80/z180/r2k/ds390/pic16/pic14/TININative/ds400/hc08 3.1.2 #7
334 (Feb 20 2012) (MINGW32)

md5.c attached.

Related

Bugs: #1996

Discussion

  • Woody

    Woody - 2012-02-21
     
  • Erik Petrich

    Erik Petrich - 2012-02-22

    This seems to be a subtle difference between c89 and c99. sdcc should now correctly compile this when operating in c89 mode. If you add the "ul" suffix to the large decimal constants, it should work in either language mode

    Fixed in revision #7340

     
  • Erik Petrich

    Erik Petrich - 2012-02-22
    • milestone: --> 100457
    • labels: 100692 --> C-Front End
    • status: open --> closed-fixed
     
  • Erik Petrich

    Erik Petrich - 2012-02-23
    • assigned_to: nobody --> epetrich
     
  • Woody

    Woody - 2012-02-24

    I tested #7347, still the same problem there.
    SDCC version: SDCC : mcs51/gbz80/z80/z180/r2k/ds390/pic16/pic14/TININative/ds400/hc08 3.1.2 #7347 (Feb 24 2012) (MINGW32)
    Command line used: sdcc md5.c -mz80 -c --std-c99 --codeseg CODE6
    I modified the md5.c to include everything in a single file for easy repeating the problem. But seems that I can not attach files when bug "fixed"?

     
  • Erik Petrich

    Erik Petrich - 2012-02-25

    Okay, I've re-openned this. It may take awhile to fix this so that it works with your source as-is in the --std-c99 mode. This is because the constants used are too large to be signed long and so according to the c99 standard must be treated as signed long long, which is currently only partially implemented.

    It worked in the older revisions of sdcc because they were interpreted with the c89 rules, which allows them to be unsigned long, but sdcc should not allow that when --std-c99 is specified. For the short term, you can change the source so that the large numbers have a "ul" suffix to force them to be of type unsigned long.

     
  • Erik Petrich

    Erik Petrich - 2012-02-25
    • milestone: 100457 -->
    • status: closed-fixed --> open
     
  • Woody

    Woody - 2012-02-25

    compileable version with everything in a file

     
  • Woody

    Woody - 2012-02-25

    I updated md5_NEW.c with everything in a file for direct compile test. I will add ul to go on test other stuff. Thanks.

     
  • Ben Shi

    Ben Shi - 2015-03-25
    • Category: --> Front-end
     
  • Ben Shi

    Ben Shi - 2015-06-17
    • status: open --> closed-duplicate
     
  • Ben Shi

    Ben Shi - 2015-06-17

    Duplicate to bug #1996.

     

Log in to post a comment.