Use of strncpy_s in dll_main.cpp

  • feddersen

    feddersen - 2007-03-31


    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) {
      strncpy(_M_name,, _S_bufsize);
      strncpy_s(_STLP_ARRAY_AND_SIZE(_M_name),, __str.size());
      _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),, _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.



Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks