I have the following code:
NTSTATUS status = STATUS_SUCCESS;
status = WdfCommonBufferCreate( // line 761
pDeviceContext->DmaEnabler,
pDeviceContext->CommonBufferSize,
WDF_NO_OBJECT_ATTRIBUTES,
&pDeviceContext->commonBuffer);
Definitions:
WDFDMAENABLER DmaEnabler;
ULONG CommonBufferSize;
WDFCOMMONBUFFER commonBuffer;
PreFast message:
hwinit.c(761) : warning 28160: Error annotation: __formal(1,Length) cannot be zero.
Found in function ‘InitializeDMA’
I know that CommonBufferSize should be size_t and not ULONG. Is PreFast warning about this, or something else?
WDK version is 7600.16385.0.
Try the following:
if ( length != 0 )
{
status = WdfCommonBufferCreate(
pDeviceContext->DmaEnabler,pDeviceContext->CommonBufferSize,
WDF_NO_OBJECT_ATTRIBUTES,&pDeviceContext->commonBuffer);
}
else
{
status = STATUS_INVALID_PARAMETER; // or what ever you want
}
–
Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
wrote in message news:xxxxx@ntdev…
>I have the following code:
>
> NTSTATUS status = STATUS_SUCCESS;
>
> status = WdfCommonBufferCreate( // line 761
> pDeviceContext->DmaEnabler,
> pDeviceContext->CommonBufferSize,
> WDF_NO_OBJECT_ATTRIBUTES,
> &pDeviceContext->commonBuffer);
>
> Definitions:
> WDFDMAENABLER DmaEnabler;
> ULONG CommonBufferSize;
> WDFCOMMONBUFFER commonBuffer;
>
> PreFast message:
> hwinit.c(761) : warning 28160: Error annotation: formal(1,Length) cannot
> be zero.
> Found in function ‘InitializeDMA’
>
> I know that CommonBufferSize should be size_t and not ULONG. Is PreFast
> warning about this, or something else?
> WDK version is 7600.16385.0.
>
>
>________ Information from ESET NOD32 Antivirus, version of virus
> signature database 4573 (20091104)
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>
Information from ESET NOD32 Antivirus, version of virus signature database 4573 (20091104) __________
The message was checked by ESET NOD32 Antivirus.
http://www.eset.com
I think that it’s saying that pDeviceContext->CommonBufferSize==0 and that it is not allowed to be.
Are you setting the value somewhere?
What I find helps to sort out some of these error messages is to look at the SAL in the header:
//
// WDF Function: WdfCommonBufferCreate
//
typedef
__checkReturn
__drv_maxIRQL(PASSIVE_LEVEL)
WDFAPI
NTSTATUS
(*PFN_WDFCOMMONBUFFERCREATE)(
__in
PWDF_DRIVER_GLOBALS DriverGlobals,
__in
WDFDMAENABLER DmaEnabler,
__in
__drv_when(Length == 0, __drv_reportError(Length cannot be zero))
size_t Length,
__in_opt
PWDF_OBJECT_ATTRIBUTES Attributes,
__out
WDFCOMMONBUFFER* CommonBuffer
);
Good luck,
mm
It also helps to look at the correct API:
__checkReturn
__drv_maxIRQL(PASSIVE_LEVEL)
NTSTATUS
FORCEINLINE
WdfCommonBufferCreate(
__in
WDFDMAENABLER DmaEnabler,
__in
__drv_when(Length == 0, __drv_reportError(Length cannot be zero))
size_t Length,
__in_opt
PWDF_OBJECT_ATTRIBUTES Attributes,
__out
WDFCOMMONBUFFER* CommonBuffer
)
My bad,
mm
Testing CommonBufferSize for 0 solved the problem. Thank you.