Windows error checking and warnings

This commit is contained in:
nhmall
2023-12-27 14:56:03 -05:00
parent 0927726900
commit 3eb0fab317
10 changed files with 286 additions and 204 deletions

View File

@@ -42,6 +42,9 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<RunCodeAnalysis>false</RunCodeAnalysis>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<RunCodeAnalysis>true</RunCodeAnalysis>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalOptions>/Gs /Oi- /w44774 %(AdditionalOptions)</AdditionalOptions>
@@ -49,7 +52,7 @@
<OmitFramePointers>true</OmitFramePointers>
<AdditionalIncludeDirectories>$(WinWin32Dir);$(IncDir);$(SysWindDir);$(SysShareDir);$(WinShareDir);$(LuaDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>TILES;_WINDOWS;DLB;MSWIN_GRAPHICS;SAFEPROCS;NOTTYGRAPHICS;SND_LIB_WINDSOUND;USER_SOUNDS;HAS_STDINT_H;PDC_WIDE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">4820;4706;4244;4245;4100;4310</DisableSpecificWarnings>
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">4820;4706;4244;4245;4100;4310;6001</DisableSpecificWarnings>
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Release|x64'">4820;4706;4244;4245;4100;4310</DisableSpecificWarnings>
</ClCompile>
<ResourceCompile>
@@ -73,7 +76,7 @@
<ClCompile Include="@(Lua)">
<DisableSpecificWarnings>4701;4702;4244;4310;4774</DisableSpecificWarnings>
<AdditionalOptions>%(AdditionalOptions) /wd4774</AdditionalOptions>
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">4701;4702;4244;4310;4774;4324</DisableSpecificWarnings>
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">4701;4702;4244;4310;4774;4324;6011;6297;6305;6385;6386;6387;28182</DisableSpecificWarnings>
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Release|x64'">4701;4702;4244;4310;4774;4324</DisableSpecificWarnings>
</ClCompile>
<ClCompile Include="$(SrcDir)allmain.c" />
@@ -147,7 +150,9 @@
<ClCompile Include="$(SrcDir)options.c" />
<ClCompile Include="$(SrcDir)o_init.c" />
<ClCompile Include="$(SrcDir)pager.c" />
<ClCompile Include="$(SrcDir)pickup.c" />
<ClCompile Include="$(SrcDir)pickup.c">
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">4820;4706;4244;4245;4100;4310;6001</DisableSpecificWarnings>
</ClCompile>
<ClCompile Include="$(SrcDir)pline.c" />
<ClCompile Include="$(SrcDir)polyself.c" />
<ClCompile Include="$(SrcDir)potion.c" />
@@ -177,7 +182,9 @@
<ClCompile Include="$(SrcDir)sys.c" />
<ClCompile Include="$(SrcDir)teleport.c" />
<ClCompile Include="$(SrcDir)tile.c" />
<ClCompile Include="$(SrcDir)timeout.c" />
<ClCompile Include="$(SrcDir)timeout.c">
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">4820;4706;4244;4245;4100;4310;6001</DisableSpecificWarnings>
</ClCompile>
<ClCompile Include="$(SrcDir)topten.c" />
<ClCompile Include="$(SrcDir)track.c" />
<ClCompile Include="$(SrcDir)trap.c" />
@@ -200,7 +207,9 @@
<ClCompile Condition="Exists('$(PDCURSES)')" Include="$(WinCursDir)cursinit.c" />
<ClCompile Condition="Exists('$(PDCURSES)')" Include="$(WinCursDir)cursinvt.c" />
<ClCompile Condition="Exists('$(PDCURSES)')" Include="$(WinCursDir)cursmain.c" />
<ClCompile Condition="Exists('$(PDCURSES)')" Include="$(WinCursDir)cursmesg.c" />
<ClCompile Condition="Exists('$(PDCURSES)')" Include="$(WinCursDir)cursmesg.c">
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">4820;4706;4244;4245;4100;4310;6001</DisableSpecificWarnings>
</ClCompile>
<ClCompile Condition="Exists('$(PDCURSES)')" Include="$(WinCursDir)cursmisc.c" />
<ClCompile Condition="Exists('$(PDCURSES)')" Include="$(WinCursDir)cursstat.c" />
<ClCompile Condition="Exists('$(PDCURSES)')" Include="$(WinCursDir)curswins.c" />
@@ -351,4 +360,4 @@
<Target Name="AfterRebuild">
<MSBuild Projects="$(vsDir)NetHack\afternethack.proj" Targets="Build" Properties="Configuration=$(Configuration)" />
</Target>
</Project>
</Project>

View File

@@ -161,7 +161,7 @@ chdrive(char* str)
char drive;
if ((ptr = strchr(str, ':')) != (char *) 0) {
drive = toupper((uchar) *(ptr - 1));
_chdrive((drive - 'A') + 1);
(void) _chdrive((drive - 'A') + 1);
}
}
@@ -388,18 +388,21 @@ void port_insert_pastebuf(char *buf)
/* Housekeeping need: +GlobalUnlock(hglbCopy), GlobalFree(hglbCopy),
CloseClipboard(), free(w) */
memcpy(lpwstrCopy, w, abytes);
GlobalUnlock(hglbCopy);
/* Housekeeping need: GlobalFree(hglbCopy), CloseClipboard(), free(w) */
if (lpwstrCopy) {
memcpy(lpwstrCopy, w, abytes);
GlobalUnlock(hglbCopy);
/* Housekeeping need: GlobalFree(hglbCopy), CloseClipboard(), free(w)
*/
/* put it on the clipboard */
hresult = SetClipboardData(CF_UNICODETEXT, hglbCopy);
if (!hresult) {
raw_printf("Error copying to clipboard.\n");
GlobalFree(hglbCopy); /* only needed if clipboard didn't accept data */
/* put it on the clipboard */
hresult = SetClipboardData(CF_UNICODETEXT, hglbCopy);
if (!hresult) {
raw_printf("Error copying to clipboard.\n");
GlobalFree(
hglbCopy); /* only needed if clipboard didn't accept data */
}
/* Housekeeping need: CloseClipboard(), free(w) */
}
/* Housekeeping need: CloseClipboard(), free(w) */
CloseClipboard();
free(w);
return;
@@ -619,30 +622,33 @@ BOOL winos_font_support_cp437(HFONT hFont)
HDC hdc = GetDC(NULL);
HFONT oldFont = SelectObject(hdc, hFont);
DWORD size = GetFontUnicodeRanges(hdc, NULL);
GLYPHSET *glyphSet = (GLYPHSET *) malloc(size);
if (glyphSet != NULL) {
GetFontUnicodeRanges(hdc, glyphSet);
DWORD size = (size_t) GetFontUnicodeRanges(hdc, NULL);
if (size) {
GLYPHSET *glyphSet = (GLYPHSET *) malloc((size_t) size);
if (glyphSet != NULL) {
#pragma warning( push )
#pragma warning( disable : 6386 )
size = GetFontUnicodeRanges(hdc, glyphSet);
#pragma warning( pop )
allFound = TRUE;
for (int i = 0; i < 256 && allFound; i++) {
WCHAR wc = cp437[i];
BOOL found = FALSE;
for (DWORD j = 0; j < glyphSet->cRanges && !found; j++) {
WCHAR first = glyphSet->ranges[j].wcLow;
WCHAR last = first + glyphSet->ranges[j].cGlyphs - 1;
allFound = TRUE;
for (int i = 0; i < 256 && allFound; i++) {
WCHAR wc = cp437[i];
BOOL found = FALSE;
for (DWORD j = 0; j < glyphSet->cRanges && !found; j++) {
WCHAR first = glyphSet->ranges[j].wcLow;
WCHAR last = first + glyphSet->ranges[j].cGlyphs - 1;
if (wc >= first && wc <= last)
found = TRUE;
if (wc >= first && wc <= last)
found = TRUE;
}
if (!found)
allFound = FALSE;
}
if (!found)
allFound = FALSE;
free(glyphSet);
}
free(glyphSet);
}
SelectObject(hdc, oldFont);
ReleaseDC(NULL, hdc);