Unlogical C6001 warning: Using uninitialized memory warning in C with Visual Studio
问题 Given this code: #include <stdlib.h> typedef struct { int *p; } MyStruct; MyStruct Test() { MyStruct ms; ms.p = malloc(sizeof(int) * 5); if (!ms.p) exit(-1); return ms; } int main(void) { while (1) { MyStruct t = Test(); free(t.p); // C6001: Using uninitialized memory 't.p'. } } Visual Studio shows C6001 warning on the free call line. However, I see there is no way to achieve the free line with the memory t.p uninitialized. What am I missing ? 回答1: Some points: sometimes SAL warnings can be