Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Use of strncpy_s in dll_main.cpp

Developers
feddersen
2007-03-31
2013-05-13
  • feddersen
    feddersen
    2007-03-31

    Hello,

    I ran into a problem passing a long string to an exception.  The problem is in dll_main.cpp, line 118

    #if defined (_STLP_OWN_STDEXCEPT)
    __Named_exception::__Named_exception(const string& __str) {
    #if !defined (_STLP_USE_SAFE_STRING_FUNCTIONS)
      strncpy(_M_name, __str.data(), _S_bufsize);
    #else
      strncpy_s(_STLP_ARRAY_AND_SIZE(_M_name), __str.data(), __str.size());
    #endif
      _M_name[_S_bufsize - 1] = '\0';
    }

    The Microsoft docs state that if count is larger then the strDest size, the string is not copied and strDest[0] is set to 0.  If you changed line 118 to read

      strncpy_s(_STLP_ARRAY_AND_SIZE(_M_name), __str.data(), _TRUNCATE);

    then strncpy_s behaves more like strncpy by copying has much of the source string as possible while setting the last character to 0.

    It does not seem logical to have e.what() return an empty string just because when a created the exception I passed in a string greater than 256 characters.

    Thanks,
    Brett