Using SAL annotations

Hello,

I just started diving in into SAL annotations and I noticed what seems like
a bug to me. I have the following functions:

void
MyFunc0(
Out_writes(NumberOfEntries) DWORD* ArrayOfStructs,
In DWORD NumberOfEntries
)
{
DWORD i;

for( i = 0; i <= NumberOfEntries; ++i )
{
ArrayOfStructs[i] = i;
}
}

void
MyFunc1(
Out_writes_bytes(sizeof(DWORD)*NumberOfEntries) DWORD*
ArrayOfStructs,
In DWORD NumberOfEntries
)
{
DWORD i;

for( i = 0; i <= NumberOfEntries; ++i )
{
ArrayOfStructs[i] = i;
}
}

void
MyFunc2(
Out_writes_all(NumberOfEntries) DWORD* ArrayOfStructs,
In DWORD NumberOfEntries
)
{
DWORD i;

for( i = 0; i <= NumberOfEntries; ++i )
{
ArrayOfStructs[i] = i;
}
}

void
MyFunc3(
Out_writes_bytes_all(sizeof(DWORD)*NumberOfEntries) DWORD*
ArrayOfStructs,
In DWORD NumberOfEntries
)
{
DWORD i;

for( i = 0; i <= NumberOfEntries; ++i )
{
ArrayOfStructs[i] = i;
}
}

Intentionally I have written the loop from 0 to NumberOfEntries to see off
by one reports from the static analyzer. Unfortunately the only place where
the warning appears is MyFunc1.

I’ve run the analyzer on these functions using Visual Studio 2013 in a user
mode, kernel mode and in a native project and the same results appear
everywhere. The rule set used by the analyzer was: “Microsoft All Rules”
which as I understand should contain all verifier checks.

Am I missing something or is this a bug?

I hope this is the correct list for posting these kind of issues.

Thanks!

I can confirm that you’re not insane, I can reproduce your observed behavior
in both VS2013 and VS2015.

Looks to me like the MyFunc0 annotation should certainly work in catching in
the error. The Windows headers use this syntax (see RtlStringCchCopyW), so I
feel like I’m missing something. Just don’t see it here though.

-scott
OSR
@OSRDrivers

“Gurzou Alexandru” wrote in message
news:xxxxx@ntdev…
Hello,

I just started diving in into SAL annotations and I noticed what seems like
a bug to me. I have the following functions:

void
MyFunc0(
Out_writes(NumberOfEntries) DWORD* ArrayOfStructs,
In DWORD NumberOfEntries
)
{
DWORD i;

for( i = 0; i <= NumberOfEntries; ++i )
{
ArrayOfStructs[i] = i;
}
}

void
MyFunc1(
Out_writes_bytes(sizeof(DWORD)NumberOfEntries) DWORD
ArrayOfStructs,
In DWORD NumberOfEntries
)
{
DWORD i;

for( i = 0; i <= NumberOfEntries; ++i )
{
ArrayOfStructs[i] = i;
}
}

void
MyFunc2(
Out_writes_all(NumberOfEntries) DWORD* ArrayOfStructs,
In DWORD NumberOfEntries
)
{
DWORD i;

for( i = 0; i <= NumberOfEntries; ++i )
{
ArrayOfStructs[i] = i;
}
}

void
MyFunc3(
Out_writes_bytes_all(sizeof(DWORD)NumberOfEntries) DWORD
ArrayOfStructs,
In DWORD NumberOfEntries
)
{
DWORD i;

for( i = 0; i <= NumberOfEntries; ++i )
{
ArrayOfStructs[i] = i;
}
}

Intentionally I have written the loop from 0 to NumberOfEntries to see off
by one reports from the static analyzer. Unfortunately the only place where
the warning appears is MyFunc1.

I’ve run the analyzer on these functions using Visual Studio 2013 in a user
mode, kernel mode and in a native project and the same results appear
everywhere. The rule set used by the analyzer was: “Microsoft All Rules”
which as I understand should contain all verifier checks.

Am I missing something or is this a bug?

I hope this is the correct list for posting these kind of issues.

Thanks!

I’ve posted an issue on connect
https://connect.microsoft.com/VisualStudio/Feedback/Details/1605316 and
Microsoft said they’re looking into it. I will inform you of the final
resolution.

On 29 July 2015 at 20:03, Scott Noone wrote:

> I can confirm that you’re not insane, I can reproduce your observed
> behavior in both VS2013 and VS2015.
>
> Looks to me like the MyFunc0 annotation should certainly work in catching
> in the error. The Windows headers use this syntax (see RtlStringCchCopyW),
> so I feel like I’m missing something. Just don’t see it here though.
>
> -scott
> OSR
> @OSRDrivers
>
> “Gurzou Alexandru” wrote in message
> news:xxxxx@ntdev…
>
> Hello,
>
> I just started diving in into SAL annotations and I noticed what seems
> like a bug to me. I have the following functions:
>
> void
> MyFunc0(
> Out_writes(NumberOfEntries) DWORD* ArrayOfStructs,
> In DWORD NumberOfEntries
> )
> {
> DWORD i;
>
> for( i = 0; i <= NumberOfEntries; ++i )
> {
> ArrayOfStructs[i] = i;
> }
> }
>
> void
> MyFunc1(
> Out_writes_bytes(sizeof(DWORD)NumberOfEntries) DWORD
> ArrayOfStructs,
> In DWORD NumberOfEntries
> )
> {
> DWORD i;
>
> for( i = 0; i <= NumberOfEntries; ++i )
> {
> ArrayOfStructs[i] = i;
> }
> }
>
> void
> MyFunc2(
> Out_writes_all(NumberOfEntries) DWORD* ArrayOfStructs,
> In DWORD NumberOfEntries
> )
> {
> DWORD i;
>
> for( i = 0; i <= NumberOfEntries; ++i )
> {
> ArrayOfStructs[i] = i;
> }
> }
>
> void
> MyFunc3(
> Out_writes_bytes_all(sizeof(DWORD)NumberOfEntries) DWORD
> ArrayOfStructs,
> In DWORD NumberOfEntries
> )
> {
> DWORD i;
>
> for( i = 0; i <= NumberOfEntries; ++i )
> {
> ArrayOfStructs[i] = i;
> }
> }
>
> Intentionally I have written the loop from 0 to NumberOfEntries to see off
> by one reports from the static analyzer. Unfortunately the only place where
> the warning appears is MyFunc1.
>
> I’ve run the analyzer on these functions using Visual Studio 2013 in a
> user mode, kernel mode and in a native project and the same results appear
> everywhere. The rule set used by the analyzer was: “Microsoft All Rules”
> which as I understand should contain all verifier checks.
>
> Am I missing something or is this a bug?
>
> I hope this is the correct list for posting these kind of issues.
>
> Thanks!
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

On 21-Aug-2015 11:34, Gurzou Alexandru wrote:

Unfortunately there has been no update by Microsoft on the issue.

Not every company is like Amazon … in some places people actually are
allowed to take their vacation days.

– pa