DXGL r831 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r830‎ | r831 | r832 >
Date:02:38, 8 July 2018
Author:admin
Status:new
Tags:
Comment:
Fix a few code analysis warnings.
Modified paths:
  • /cfgmgr/cfgmgr.c (modified) (history)
  • /dxglcfg-old/dxglcfg-old.c (modified) (history)
  • /dxglcfg/dxglcfg.cpp (modified) (history)
  • /dxglcfg/dxgltest.cpp (modified) (history)

Diff [purge]

Index: cfgmgr/cfgmgr.c
@@ -24,9 +24,6 @@
2525 #include <stdio.h>
2626 #include <Windows.h>
2727 #include <ShellAPI.h>
28 -#ifndef LSTATUS
29 -typedef LONG LSTATUS;
30 -#endif
3128 #include "crc32.h"
3229 #include "LibSha256.h"
3330 #include "cfgmgr.h"
@@ -109,6 +106,11 @@
110107 DialogBox(hddraw, MAKEINTRESOURCE(IDD_COMPAT), NULL, CompatDialogCallback);
111108 cmdline = GetCommandLine();
112109 cmdline2 = (LPTSTR)malloc((_tcslen(cmdline) + 1)*sizeof(TCHAR));
 110+ if (!cmdline2)
 111+ {
 112+ MessageBox(NULL, _T("Fatal error restarting application"), _T("Out of memory"), MB_OK | MB_ICONSTOP);
 113+ ExitProcess(ERROR_NOT_ENOUGH_MEMORY);
 114+ }
113115 _tcscpy(cmdline2, cmdline);
114116 ZeroMemory(&startupinfo, sizeof(STARTUPINFO));
115117 startupinfo.cb = sizeof(STARTUPINFO);
@@ -882,7 +884,7 @@
883885 sha256string[256 / 4] = 0;
884886 _tcscat(regkey, sha256string);
885887 error = RegOpenKeyEx(HKEY_CURRENT_USER, regkey, 0, KEY_READ, &hKey);
886 - if (error = ERROR_SUCCESS)
 888+ if (error == ERROR_SUCCESS)
887889 {
888890 RegCloseKey(hKey);
889891 return TRUE;
@@ -902,6 +904,7 @@
903905 int i;
904906 TCHAR filename[MAX_PATH + 1];
905907 _tcsncpy(pathlwr, path, MAX_PATH);
 908+ pathlwr[MAX_PATH] = 0;
906909 for (i = _tcslen(pathlwr); (i > 0) && (pathlwr[i] != 92) && (pathlwr[i] != 47); i--);
907910 pathlwr[i] = 0;
908911 _tcslwr(pathlwr);
@@ -1276,6 +1279,7 @@
12771280 strcat(floatformat, number);
12781281 strcat(floatformat, "g");
12791282 _snprintf(number, 31, floatformat, value);
 1283+ number[31] = 0;
12801284 strcat(buffer, number);
12811285 strcat(buffer, "\r\n");
12821286 buffersize = strlen(buffer);
@@ -1457,7 +1461,7 @@
14581462 {
14591463 while (1)
14601464 {
1461 - ReadFile(file2, buffer, 512, &bytesread, NULL);
 1465+ if(!ReadFile(file2, buffer, 512, &bytesread, NULL)) break;
14621466 if (!bytesread) break;
14631467 Sha256Update(&sha_context, buffer, bytesread);
14641468 if (bytesread < 512) break;
@@ -1564,7 +1568,7 @@
15651569 HMODULE hSHCore = NULL;
15661570 HMODULE hUser32 = NULL;
15671571 HRESULT(WINAPI *_SetProcessDpiAwareness)(DWORD value);
1568 - BOOL(WINAPI *_SetProcessDpiAwarenessContext)(HANDLE value);
 1572+ BOOL(WINAPI *_SetProcessDpiAwarenessContext)(HANDLE value) = NULL;
15691573 BOOL(WINAPI *_SetProcessDPIAware)();
15701574 GetModuleFileName(NULL, filename, MAX_PATH);
15711575 _tcscpy(regkey, regkeybase);
Index: dxglcfg/dxglcfg.cpp
@@ -4267,7 +4267,7 @@
42684268 icc.dwSize = sizeof(icc);
42694269 icc.dwICC = ICC_WIN95_CLASSES;
42704270 comctl32 = LoadLibrary(_T("comctl32.dll"));
4271 - iccex = (BOOL (WINAPI *)(LPINITCOMMONCONTROLSEX))GetProcAddress(comctl32,"InitCommonControlsEx");
 4271+ if (comctl32) iccex = (BOOL (WINAPI *)(LPINITCOMMONCONTROLSEX))GetProcAddress(comctl32,"InitCommonControlsEx");
42724272 if(iccex) iccex(&icc);
42734273 else InitCommonControls();
42744274 hinstance = hInstance;
Index: dxglcfg/dxgltest.cpp
@@ -152,10 +152,10 @@
153153 case WM_INITDIALOG:
154154 if (_EnableThemeDialogTexture) _EnableThemeDialogTexture(hWnd, ETDT_ENABLETAB);
155155 mod_ddraw = LoadLibrary(_T("ddraw.dll"));
156 - IsDXGLDDraw = GetProcAddress(mod_ddraw,"IsDXGLDDraw");
 156+ if(mod_ddraw) IsDXGLDDraw = GetProcAddress(mod_ddraw,"IsDXGLDDraw");
157157 if(IsDXGLDDraw) SetWindowText(GetDlgItem(hWnd,IDC_DDTYPE),_T("DXGL"));
158158 else SetWindowText(GetDlgItem(hWnd,IDC_DDTYPE),_T("System"));
159 - FreeLibrary(mod_ddraw);
 159+ if(mod_ddraw) FreeLibrary(mod_ddraw);
160160 GetFileVersion(ver,dllnames[0]);
161161 SetWindowText(GetDlgItem(hWnd,dllboxes[0]),ver.c_str());
162162 if(!IsDXGLDDraw)
Index: dxglcfg-old/dxglcfg-old.c
@@ -1884,7 +1884,7 @@
18851885 icc.dwSize = sizeof(icc);
18861886 icc.dwICC = ICC_WIN95_CLASSES;
18871887 comctl32 = LoadLibrary(_T("comctl32.dll"));
1888 - iccex = (BOOL (WINAPI *)(LPINITCOMMONCONTROLSEX))GetProcAddress(comctl32,"InitCommonControlsEx");
 1888+ if(comctl32) iccex = (BOOL (WINAPI *)(LPINITCOMMONCONTROLSEX))GetProcAddress(comctl32,"InitCommonControlsEx");
18891889 if(iccex) iccex(&icc);
18901890 else InitCommonControls();
18911891 hinstance = hInstance;