Menu

#169 Microsoft Visual C++ C4996 May Be Unsafe Warnings

0.60
closed
nobody
None
5
2011-06-26
2011-05-17
No

Try this patch if you're getting C4996 (may be unsafe) Warnings when compiling with Microsoft Visual C++.

Discussion

  • Stephen J. Muir

    Stephen J. Muir - 2011-05-17
     
  • Kevin Atkinson

    Kevin Atkinson - 2011-05-18

    I am not sure if I am going to accept this patch. You are using non-standard windows only functions and adding a lot a clutter to the source code which will make it more difficult to maintain.

    I might accept a patch which doesn't use so many preprocessor conditionals.
    Based on http://msdn.microsoft.com/en-us/library/8ef0s5kh\(v=vs.80).aspx it seams that
    _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES can be defined. I suggest you do this in a common header file such as "settings.h".

     
  • Stephen J. Muir

    Stephen J. Muir - 2011-05-18

    Understood, but setting _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES prevents these functions from properly checking for buffer overruns at run-time.

    For example, with:

    char *cp;
    // some stuff here which could assign to or increment cp
    strcpy(cp, "appendage");

    There's no way for any macro to know how much space is available in the output buffer.

     
  • Kevin Atkinson

    Kevin Atkinson - 2011-05-18

    My original comment still holds.

    In the example you just gave, if the size of "cp" can not be determined at compile time to be large enough its better to use strncpy. Or manually check that the size is correct.

    Maybe its best just to suppress C4996 when compiling Aspell.

     
  • Kevin Atkinson

    Kevin Atkinson - 2011-06-26
    • status: open --> closed
     
  • Kevin Atkinson

    Kevin Atkinson - 2011-06-26

    I am going to close this report. I might accept something which doesn't use so many conditionals. If you wish to offer a more palatable patch please reopen this bug or just create a new report.