문제

I have been reading about SAL and I'm not clear on if annotations on pointer types apply to the reference or the value it points to. For example, if I have:

void f(_In_ type* t);

_In_ means "The parameter must be valid in pre-state and will not be modified." Does its application here mean that the address of t will not change, or the value of t?

도움이 되었습니까?

해결책

In your example, _In_ means that

  • VS Code Analysis will validate that callers pass a non-null pointer to an initialized buffer.
  • VS Code Analysis will not validate that t is checked for null before dereferencing it in the function; t is assumed to be non-null in the function itself. By changing _In_ to _In_opt_, VS Code Analysis will validate that t is checked for null before dereferencing it.
  • VS Code Analysis will validate that the function only reads "one element" of type from the memory pointed at by t, like assigning the value of the dereferenced pointer to a variable.
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top