Click here to Skip to main content
15,898,939 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: sorce code grid line Pin
SADEGH20771-Aug-20 10:09
SADEGH20771-Aug-20 10:09 
GeneralRe: sorce code grid line Pin
Victor Nijegorodov1-Aug-20 10:37
Victor Nijegorodov1-Aug-20 10:37 
GeneralRe: sorce code grid line Pin
SADEGH20772-Aug-20 7:03
SADEGH20772-Aug-20 7:03 
GeneralRe: sorce code grid line Pin
Victor Nijegorodov2-Aug-20 7:11
Victor Nijegorodov2-Aug-20 7:11 
GeneralRe: sorce code grid line Pin
SADEGH20772-Aug-20 7:14
SADEGH20772-Aug-20 7:14 
GeneralRe: sorce code grid line Pin
Victor Nijegorodov2-Aug-20 7:28
Victor Nijegorodov2-Aug-20 7:28 
GeneralRe: sorce code grid line Pin
Dave Kreskowiak1-Aug-20 12:03
mveDave Kreskowiak1-Aug-20 12:03 
GeneralRe: sorce code grid line Pin
David Crow3-Aug-20 2:58
David Crow3-Aug-20 2:58 
GeneralRe: sorce code grid line Pin
Greg Utas3-Aug-20 3:06
professionalGreg Utas3-Aug-20 3:06 
AnswerRe: sorce code grid line Pin
Richard MacCutchan3-Aug-20 5:12
mveRichard MacCutchan3-Aug-20 5:12 
QuestionIn c++ How to deny usb read write? Pin
Member 1487268126-Jul-20 17:30
Member 1487268126-Jul-20 17:30 
QuestionRe: In c++ How to deny usb read write? Pin
David Crow27-Jul-20 2:49
David Crow27-Jul-20 2:49 
AnswerRe: In c++ How to deny usb read write? Pin
Member 1487268127-Jul-20 15:27
Member 1487268127-Jul-20 15:27 
GeneralRe: In c++ How to deny usb read write? Pin
Dave Kreskowiak27-Jul-20 16:29
mveDave Kreskowiak27-Jul-20 16:29 
GeneralRe: In c++ How to deny usb read write? Pin
Member 1487268127-Jul-20 16:53
Member 1487268127-Jul-20 16:53 
GeneralRe: In c++ How to deny usb read write? Pin
Dave Kreskowiak27-Jul-20 18:16
mveDave Kreskowiak27-Jul-20 18:16 
GeneralRe: In c++ How to deny usb read write? Pin
Member 1487268127-Jul-20 18:29
Member 1487268127-Jul-20 18:29 
QuestionQueryBinaryValue to CByteArray Pin
_Flaviu24-Jul-20 4:19
_Flaviu24-Jul-20 4:19 
AnswerRe: QueryBinaryValue to CByteArray Pin
Mircea Neacsu24-Jul-20 4:28
Mircea Neacsu24-Jul-20 4:28 
GeneralRe: QueryBinaryValue to CByteArray Pin
_Flaviu24-Jul-20 5:16
_Flaviu24-Jul-20 5:16 
AnswerRe: QueryBinaryValue to CByteArray Pin
Victor Nijegorodov25-Jul-20 23:16
Victor Nijegorodov25-Jul-20 23:16 
QuestionVS2019, Code analysis warning: C6385 mystery Pin
QuiJohn23-Jul-20 2:39
QuiJohn23-Jul-20 2:39 
This is the full warning in question:
warning C6385: Reading invalid data from 'lines': the readable size is '(unsigned int)*4+4' bytes, but '8' bytes may be read.

I just (finally) converted a VS2013 project to VS2019, and as part of the cleanup I've been running the code analysis to help me spot issues. Below is a minimalist version of an oddity I found.

So here's the case that started the journey. You can assume m_iNumLines is a UINT greater than 0; checking for this and other error conditions (e.g. that the pointer is not NULL) did not eliminate the warning. Simplified for clarity, this is verbatim code that triggered the warning:

void CTestClass::SetText()
{
    CString* lines = new CString[m_iNumLines];

    for (UINT i = 0; i < m_iNumLines; i++)
    {
        // Case 1: warning C6385: Reading invalid data from 'lines':  the readable size is 
        //         '(unsigned int)*4+4' bytes, but '8' bytes may be read.
        lines[i] = "TestString";
    }

    delete[] lines;
}


I first tried covering every last (even absurd) error case to try and eliminate the warning, but changing lines[i] to *(lines + i) did it:

void CTestClass::SetText()
{
    CString* lines = new CString[m_iNumLines];

    for (UINT i = 0; i < m_iNumLines; i++)
    {
        // Case 2: No warning
        *(lines + i) = "TestString";
    }

    delete[] lines;
}


I'm not sure what about handling of CStrings & pointers would make that an improvement. But here's what really baked my noodle. If I leave both lines in - even with the code that triggered thee warning first - I no longer get the warning:

void CTestClass::SetText()
{
    CString* lines = new CString[m_iNumLines];

    for (UINT i = 0; i < m_iNumLines; i++)
    {
        // Case 3: *ALSO* No warning
        lines[i] = "TestString";
        *(lines + i) = "TestString2";
    }

    delete[] lines;
}


I also get no warning if I swapped the order (thinking maybe optimization - even in a debug build - made the first line do nothing).

In searching I found others getting this warning also when using CStrings, but in situations much more convoluted than this, and I didn't see how it explained my case. Also I get the same results when using std::string, for what it's worth.
Look at me still talking when there's science to do
When I look out there it makes me glad I'm not you

AnswerRe: VS2019, Code analysis warning: C6385 mystery Pin
Richard MacCutchan23-Jul-20 5:53
mveRichard MacCutchan23-Jul-20 5:53 
AnswerRe: VS2019, Code analysis warning: C6385 mystery Pin
Joe Woodbury23-Jul-20 9:10
professionalJoe Woodbury23-Jul-20 9:10 
Questionvs2019 + v71 + v80 Pin
hmd-omani20-Jul-20 19:50
hmd-omani20-Jul-20 19:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.