diff --git a/dlls/user32/menu.c b/dlls/user32/menu.c index 50545eef42c..bbaa5f367f9 100644 --- a/dlls/user32/menu.c +++ b/dlls/user32/menu.c @@ -4795,8 +4795,8 @@ static BOOL MENU_NormalizeMenuItemInfoStruct( const MENUITEMINFOW *pmii_in, MENUITEMINFOW *pmii_out ) { /* do we recognize the size? */ - if( pmii_in->cbSize != sizeof( MENUITEMINFOW) && - pmii_in->cbSize != sizeof( MENUITEMINFOW) - sizeof( pmii_in->hbmpItem)) { + if( !pmii_in || (pmii_in->cbSize != sizeof( MENUITEMINFOW) && + pmii_in->cbSize != sizeof( MENUITEMINFOW) - sizeof( pmii_in->hbmpItem)) ) { SetLastError( ERROR_INVALID_PARAMETER); return FALSE; } diff --git a/dlls/user32/tests/menu.c b/dlls/user32/tests/menu.c index 20126d49490..d02eb9157f8 100644 --- a/dlls/user32/tests/menu.c +++ b/dlls/user32/tests/menu.c @@ -948,6 +948,19 @@ static void test_menu_add_string( void ) ok (!lstrcmpW( strbackW, expectedString ), "Menu text from Unicode version incorrect\n"); } + /* Just try some invalid parameter tests */ + SetLastError(0xdeadbeef); + rc = SetMenuItemInfoA( hmenu, 0, TRUE, NULL ); + ret = GetLastError(); + ok (!rc, "SetMenuItemInfoA succeeded unexpectedly\n"); + ok (ret == ERROR_INVALID_PARAMETER, "Expected 87, got %d\n", ret); + + SetLastError(0xdeadbeef); + rc = SetMenuItemInfoA( hmenu, 0, FALSE, NULL ); + ret = GetLastError(); + ok (!rc, "SetMenuItemInfoA succeeded unexpectedly\n"); + ok (ret == ERROR_INVALID_PARAMETER, "Expected 87, got %d\n", ret); + /* Just change ftype to string and see what text is stored */ memset(&info, 0x00, sizeof(info)); info.cbSize= sizeof(MENUITEMINFOA);