#33 missing intsafe.h

open-accepted
Kai Tietz
Headers (17)
5
2015-08-01
2010-06-01
tta
No

I did write one for MinGW. Please see the attached archive for details. Though it is still not well-tested and may have bugs or typos.

Discussion

  • tta
    tta
    2010-06-01

    headers for intsafe.h functions

     
    Attachments
  • Kai Tietz
    Kai Tietz
    2010-06-15

    Thank you for your contribution. I'll look in more detail to your suggested implementation and will come back to this later.

    Kai

     
  • NightStrike
    NightStrike
    2010-10-14

    • labels: --> Headers
    • assigned_to: nobody --> ktietz70
    • status: open --> open-accepted
     
  • NightStrike
    NightStrike
    2010-10-14

    Kai, did you commit this change at all?

     
  • David Grayson
    David Grayson
    2015-04-23

    I am trying to build Microsoft's USBView application with mingw-w64 (using MSYS2) and the lack of intsafe.h is the first problem I encountered.

     
    Last edit: David Grayson 2015-04-23
  • David Grayson
    David Grayson
    2015-07-25

    Thanks for your contribution, tta. I will push for this to get added to mingw-w64. I confirmed (using bash and grep) that it has every function that is documented by Microsoft, and I was able to compile it under the latest version of mingw-w64 fairly easily. You can follow my progress on building/testing it here:

    https://github.com/DavidEGrayson/intsafe

    I'll also post on the mingw-w64 mailing list at some point.

     
    Last edit: David Grayson 2015-07-25
  • David Grayson
    David Grayson
    2015-08-01

    Actually, I spotted this line in tta's implementation, in intsafe_64.h:

    int64_t tmp = (int64_t)(op1 + op2);
    

    Since op1 and op2 are signed integers (which can be seen from context I did not include here), and signed integer overflow is undefined behavior, the line above is dangerous and should not be used. Here is an example of what can go wrong if you use code like that:

    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=30475

    At this time, I recommend that people avoid using tta's intsafe.h.

    I am working on a better one over at https://github.com/DavidEGrayson/intsafe

     
    Last edit: David Grayson 2015-08-01