Update assert-asserte-assert-expr-macros.md#4850
Conversation
1) In dynamic memory allocation parts arise the "null pointer dereferencing" which can cause to undefined behaviour later. The first appeal to the memory by null pointer or in a differ terms dereferencing the null pointer usually causes the "structured exception" in Windows systems. In "Microsoft Visual Studio Community 2019 Version 16.11.29" environment compiler generates "Warning C6387" coherented with "NULL values of p1, p2", since p1, p2 are separately the arguments of strcpy_s and due to SAL for strcpy_s function the p1, p2 can not be NULL which maybe related indirectly with "Warning C6011" where it took its initial point which corresponds to "null pointer dereferencing":
// string.h
_Check_return_wat_
_ACRTIMP errno_t __cdecl strcpy_s(
_Out_writes_z_(_SizeInBytes) char* _Destination,
_In_ rsize_t _SizeInBytes,
_In_z_ char const* _Source
);
P.S.: if statements could be replaced respectively with:
_ASSERT(p1 != NULL);
_ASSERT(p2 != NULL);
2) Initialized the pointers to NULL;
|
@shalala66 : Thanks for your contribution! The author(s) have been notified to review your proposed change. |
|
Learn Build status updates of commit b8f8f07: ✅ Validation status: passed
For more details, please refer to the build report. For any questions, please:
|
|
Hi, @shalala66. Thank you for taking an interest in the docs. |
|
Hi, @TylerMSFT. These commits are about good practice even in demo code. This entire code snippet is not correct. Pointer initialization is also important in the all cases. It's potential wild pointer which is a uninitialized pointer till its first use hence by default it then hold some arbitrary memory location, and attempting to do any operation using it could be cause to crash of program. People learn from this platform and accepted this place as serious, since this site by Microsoft, but You ignore the necessary changings. |
P.S.: if statements could be replaced respectively with:
P.S.: In C23 it could be initialized as nullptr:
https://en.cppreference.com/w/c/compiler_support/23#:~:text=13-,nullptr,-N3042