none
Question about Code Analysis for Kernel Driver RRS feed

  • Question

  • When running the driver analyzer, I get a C6001 Using unitialized memory error on the code below. I can't see the error, would appreciate any help. The specific error is "148 (the line with new WCHAR) '*_Param_(1)->Buffer' is not initialized" then "153 (the line with RtlCopyUnicodeString) '*_Param_(1)->Buffer is used, but may not have been initialized"

     explicit ustring(const UNICODE_STRING &From)
     {
    	Length = MaximumLength = 0 ;
    	if ( From.Length)
    	{
    		Buffer = new WCHAR [ From.Length ] ;
    		if ( Buffer )
    		{
    			Length = MaximumLength = From.Length * sizeof ( WCHAR ) ;
    			RtlCopyUnicodeString(this, &From);
    		}
    	 }
      }
    

    Thursday, August 23, 2012 2:37 PM

All replies

  • Hi,

    Can you first help getting your snippet to compile.  This is as close as I could get:

    #include <wdm.h>
    
    class ustring
    {
    	int Length;
    	int MaximumLength;
    	WCHAR* Buffer;
    
    public:
    	explicit ustring(const UNICODE_STRING &From)
    	{
    		Length = MaximumLength = 0 ;
    		if ( From.Length)
    		{
    			Buffer = new WCHAR [ From.Length ] ; // Line 148
    			if ( Buffer )
    			{
    				Length = MaximumLength = From.Length * sizeof ( WCHAR ) ;
    				RtlCopyUnicodeString(this, &From); // Line 153
    			}
    		}
    	}
    };
    

    This gives me a Error 1 error C2664: 'RtlCopyUnicodeString' : cannot convert parameter 1 from 'ustring *const ' to 'PUNICODE_STRING' on line 153.

    Thanks,

    - Jakob

    Thursday, August 23, 2012 8:55 PM
  • Length and MaximumLength are USHORT (a.k.a. RTL_STRING_LENGTH_TYPE ).

    Perhaps it should be:

    class ustring: UNICODE_STRING { .... }

    -- pa

    Thursday, August 23, 2012 9:52 PM
  • Pavel,

    Spot on and thanks lots!!!  ustring is definitely supposed to be a sub-class of UNICODE_STRING.  With this I can compile:

    #include <wdm.h>
    
    class ustring : public UNICODE_STRING
    {
    	USHORT Length;
    	USHORT MaximumLength;
    	WCHAR* Buffer;
    
    public:
    	explicit ustring(const UNICODE_STRING &From)
    	{
    		Length = MaximumLength = 0 ;
    		if ( From.Length)
    		{
    			Buffer = new WCHAR [ From.Length ] ; // Line 148
    			if ( Buffer )
    			{
    				Length = MaximumLength = From.Length * sizeof ( WCHAR ) ;
    				RtlCopyUnicodeString(this, &From); // Line 153
    			}
    		}
    	}
    };

    However I do not repro andinc's issue.  I am getting "No code analysis issues were detected".  I am using Visual Studio 2012 RTM and Windows 8 WDK RTM.

    Thanks,

    - Jakob


    Thursday, August 23, 2012 11:00 PM
  • Sorry, I was hoping it was an obvious error that I just could not see. Here is the original code with the correct derived type:

    struct ustring : UNICODE_STRING
    {
      ustring(void)
      {
        Buffer        = NULL;
        Length        = 0;
        MaximumLength = 0;
      }
    
      ustring(const ustring &From)
      {
        Buffer        = new WCHAR[From.Length];
        MaximumLength = (Buffer) ? From.Length * sizeof(WCHAR) : 0;
        Length        = MaximumLength;
    
        RtlCopyUnicodeString(this, &From);
      }
    
    The error is reported as Warning : C6001: Using uninitialized memory '*_Param_(1)->Buffer' on the RtlCopyUnicodeString function.
    Friday, August 24, 2012 1:51 AM
  • what version and release of VS and the windows 8 WDK are you using ? RTM, RC (Release Preview), Beta (Consumer Preview) ?

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Friday, August 24, 2012 4:37 AM
  • Windows 8 is RTM x64. VS is Version 11.0.50727.1 RTMREL.

    Mike A


    • Edited by andinc Thursday, September 27, 2012 8:53 AM
    Thursday, September 27, 2012 8:41 AM
  • and you are still seeing this error? how did you create this project? through the conversion tool or file | new project and from a template or blank project?

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Thursday, September 27, 2012 4:38 PM
  • Through the conversion tool.
    Friday, November 23, 2012 3:32 AM