https://git.reactos.org/?p=reactos.git;a=commitdiff;h=db416e3914271a96cdc84…
commit db416e3914271a96cdc84b0e82df0bff34ce52c7
Author: Serge Gautherie <reactos-git_serge_171003(a)gautherie.fr>
AuthorDate: Thu Nov 12 01:22:46 2020 +0100
Commit: George Bișoc <george.bisoc(a)reactos.org>
CommitDate: Sat Apr 24 20:35:48 2021 +0200
[REACTOS] InitImageList(): Fix error checks
And simplify code a bit.
---
base/applications/mscutils/servman/misc.c | 3 +--
dll/cpl/mmsys/sounds.c | 3 +--
modules/rosapps/applications/imagesoft/misc.c | 24 +++++++++++++++++++-----
modules/rostests/winetests/GUI/misc.c | 5 +++--
4 files changed, 24 insertions(+), 11 deletions(-)
diff --git a/base/applications/mscutils/servman/misc.c
b/base/applications/mscutils/servman/misc.c
index e41f3183e0e..d34fcfca9a1 100644
--- a/base/applications/mscutils/servman/misc.c
+++ b/base/applications/mscutils/servman/misc.c
@@ -247,8 +247,7 @@ InitImageList(UINT StartResource,
LR_LOADTRANSPARENT);
if (hImage == NULL)
{
- ImageList_Destroy(himl);
- himl = NULL;
+ ret = -1;
break;
}
diff --git a/dll/cpl/mmsys/sounds.c b/dll/cpl/mmsys/sounds.c
index 89df8727728..b59814d92a1 100644
--- a/dll/cpl/mmsys/sounds.c
+++ b/dll/cpl/mmsys/sounds.c
@@ -1056,8 +1056,7 @@ InitImageList(UINT StartResource,
LR_LOADTRANSPARENT);
if (hImage == NULL)
{
- ImageList_Destroy(himl);
- himl = NULL;
+ ret = -1;
break;
}
diff --git a/modules/rosapps/applications/imagesoft/misc.c
b/modules/rosapps/applications/imagesoft/misc.c
index f71f95f6eb0..4b72006152f 100644
--- a/modules/rosapps/applications/imagesoft/misc.c
+++ b/modules/rosapps/applications/imagesoft/misc.c
@@ -374,11 +374,11 @@ ToolbarInsertSpaceForControl(HWND hWndToolbar,
HIMAGELIST
InitImageList(UINT NumImages, UINT StartResource)
{
+ UINT EndResource = StartResource + NumImages - 1;
HBITMAP hBitmap;
HIMAGELIST hImageList;
- UINT i, k;
- INT Ret;
- DBG_UNREFERENCED_LOCAL_VARIABLE(Ret);
+ UINT i;
+ INT Ret = 0;
/* Create the toolbar icon image list */
hImageList = ImageList_Create(TB_BMP_WIDTH,
@@ -386,11 +386,11 @@ InitImageList(UINT NumImages, UINT StartResource)
ILC_MASK | ILC_COLOR24,
NumImages,
0);
- if (! hImageList)
+ if (hImageList == NULL)
return NULL;
/* Add all icons to the image list */
- for (i = StartResource, k = 0; k < NumImages; i++, k++)
+ for (i = StartResource; i <= EndResource; i++)
{
hBitmap = LoadImage(hInstance,
MAKEINTRESOURCE(i),
@@ -398,12 +398,26 @@ InitImageList(UINT NumImages, UINT StartResource)
TB_BMP_WIDTH,
TB_BMP_HEIGHT,
LR_LOADTRANSPARENT);
+ if (hBitmap == NULL)
+ {
+ Ret = -1;
+ break;
+ }
Ret = ImageList_AddMasked(hImageList,
hBitmap,
RGB(255, 255, 254));
DeleteObject(hBitmap);
+
+ if (Ret == -1)
+ break;
+ }
+
+ if (Ret == -1)
+ {
+ ImageList_Destroy(hImageList);
+ hImageList = NULL;
}
return hImageList;
diff --git a/modules/rostests/winetests/GUI/misc.c
b/modules/rostests/winetests/GUI/misc.c
index 7830f277315..dfe436b7735 100644
--- a/modules/rostests/winetests/GUI/misc.c
+++ b/modules/rostests/winetests/GUI/misc.c
@@ -249,10 +249,11 @@ InitImageList(UINT StartResource,
Ret = ImageList_AddIcon(hImageList,
hIcon);
- if (Ret == -1)
- goto fail;
DestroyIcon(hIcon);
+
+ if (Ret == -1)
+ goto fail;
}
return hImageList;