无法摆脱夹板警告"Field used before definition","rvalue is used that may not be initialized to a value on some execution"

Can't get rid of splint warning "Field used before definition", "rvalue is used that may not be initialized to a value on some execution"

我正在努力摆脱以下代码的夹板警告:

void GetPrinterInfo(HANDLE hPrinter){
    PRINTER_INFO_4* pPrinterInfo = NULL;
    DWORD bytesNeeded;

    GetPrinter(hPrinter, 4, NULL, 0, &bytesNeeded);

    pPrinterInfo = malloc(bytesNeeded);

    if (GetPrinter(hPrinter, 4, (LPVOID)(pPrinterInfo), bytesNeeded, &bytesNeeded)){
        printf("Printer name: %S", pPrinterInfo->pPrinterName);
    }

    free(pPrinterInfo);
}

警告是(在 "printf" 行):

Field pPrinterInfo->pPrinterName used before definition

1> An rvalue is used that may not be initialized to a value on some execution

大概它假设 pPrinter 还没有被填充。我尝试用 /*@out@*/s 等标记 SetPrinter 的 header 定义,但没有帮助。我在 header 文件中尝试了一堆注释,例如 /*@temp@*//*@dependent@*/ 无济于事。

我如何明智地让 splint 知道 pPrinter 字段在调用 GetPrinter 后应该有效?

仍然不清楚为什么带有 out 注释的 SetPrinter 不起作用。然而,一个可接受的解决方法(来自 user3386109)是只清空内存,以便夹板将其视为已初始化:

pPrinterInfo = malloc(bytesNeeded);

ZeroMemory(pPrinterInfo, bytesNeeded);

if (GetPrinter(hPrinter, 4, (LPVOID)(pPrinterInfo), bytesNeeded, &bytesNeeded)){

其中 ZeroMemory 只是 memset 的别名。

这并不理想,如果不采取额外措施来修复此警告会更好,但它对我的情况有用。