Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

VS2012 - Code Analysis C6255 for conversion from CString to const char *

$
0
0

Hello,

#include <atlstr.h> int main() { CString str = _T("whatever"); USES_CONVERSION; const char * cnstChar = T2A((LPCTSTR)str);

}

Code Analysis with 'Microsoft All Rules' generates next warning:
source.cpp(7): warning : C6255: _alloca indicates failure by raising a stack overflow exception.  Consider using _malloca instead.

As it's on unicode, T2A is a define for W2A.
And W2A is defined in atlconv.h as:

#define W2A(lpw) (\ ((_lpw = lpw) == NULL) ? NULL : (\ (_convert = (static_cast<int>(wcslen(_lpw))+1), \ (_convert>INT_MAX/2) ? NULL : \ ATLW2AHELPER((LPSTR) alloca(_convert*sizeof(WCHAR)), _lpw, _convert*sizeof(WCHAR), _acp))))

So how to avoid that warning as it comes from a system header? Is there a better way to convert CString? If yes, why is my case bad?

Best regards,


Viewing all articles
Browse latest Browse all 15302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>