0

I'm trying to compile a bit of code that looks something like so: (examples starts on line 38, throw is 45)

VSShader::VSShader(_In_ ICore * const pCore, _In_ const String & path, _In_opt_ const char ** ppArgs) :
    m_Core(pCore), m_Name(path), m_DefaultTechnique(nullptr)
{
    CGcontext context = m_Core->GetCgContext();

    if (!context || !cgIsContext(context))
    {
        throw Exception(L"Voodoo/Core", L"Unable to create parameter (core has no context).", pCore, "VSShader.cpp",  __FUNCTION__  , 45);
    }

    int32_t len = m_Name.ToCharStr(0, nullptr);
    std::vector<char> buffer(len);
    path.ToCharStr(len, &buffer[0]);

    m_CgEffect = cgCreateEffectFromFile(context, &buffer[0], ppArgs);

    if (!cgIsEffect(m_CgEffect))
    {
        throw Exception(L"Voodoo/Core", L"Failed to create shader.", m_Core, "VSShader.cpp",  __FUNCTION__  , 56);
    }
    else
    {
        cgSetEffectName(m_CgEffect, &buffer[0]);
    }

    this->Link();
}

The ctor being called looks like:

Exception
(
    _In_ wchar_t * Module,
    _In_ wchar_t * Message,
    _In_opt_ ICore * pCore,
    _In_ char * File,
    _In_ char * Function,
    _In_ int Line
);

When I run analysis on this, I get the error:

1>d:\code\voodooshader\framework\core\vsshader.cpp(45): warning C6385: Invalid data: accessing 'argument 3', the readable size is '1*0' bytes, but '4' bytes might be read: Lines: 40, 39, 41, 43

As best as I can tell, that's claiming the pointer has 0 readable bytes, and I'm trying to use 4 of those when passing it (incorrect and correct, respectively). This is a 32-bit build, so pointers should be 4 bytes.

If I change the m_Core in the throw to nullptr, I receive no errors anywhere, not just on the throw line (lines 39-41 & 43 also suddenly lack errors).

Even more unusual, if I comment out the throw entirely, I receive:

1>d:\code\voodooshader\framework\core\vsshader.cpp(56): warning C6385: Invalid data: accessing 'argument 3', the readable size is '1*0' bytes, but '4' bytes might be read: Lines: 40, 39, 41, 43, 48, 49, 50, 52, 54

This gives the same error on seemingly unrelated lines.

The MSDN example for the error appears unrelated in any meaningful way, discussing bad array access.

Is this a known error of some kind, a bug, or am I simply misreading it?

More importantly, how can I fix it (this is the only warning from the compiler or PREfast, on /w4 /wX, in an 11kloc codebase, because it loves to heap on the hateful irony :P).

Edit: After some discussion and testing, I've discovered two additional oddities:

If I remove the annotations entirely from the _In_ ICore* const pCore parameter, there is no error.

If I change the annotation on that parameter to _Pre_notnull_ ICore * const pCore, there is also no error. _Pre_notnull_ has most of the requirements of _In_, so this is a functional solution for the time being, but does not seem correct.

ssube
  • 47,010
  • 7
  • 103
  • 140

1 Answers1

0

http://social.msdn.microsoft.com/forums/en-US/vstscode/thread/0505289d-4501-4f99-bc06-650c6b481566

Visual Studio bug. Warning supression example in link above. It has not been fixed in VS2010 yet!

dysonfree
  • 108
  • 3
  • 11