]> granicus.if.org Git - nethack/commitdiff
#R675: bug in win32 GUI (division by zero)
authornethack.allison <nethack.allison>
Sun, 24 Mar 2002 23:53:28 +0000 (23:53 +0000)
committernethack.allison <nethack.allison>
Sun, 24 Mar 2002 23:53:28 +0000 (23:53 +0000)
(from <Someone>)

>The tile size is actually set just once in mhmap.c so validation can be done
>in one place. The patch is attached.
>
><email deleted>
on Sunday, March 24, 2002 at 16:15:50
---------------------------------------------------------------------------

mailversion: 1.10

nhversion: 3.4.0

nhfrom: 3.4.0 Official binary release for Windows 95/98/NT/2000/Me/XP
(nh340win.zip)

hardware: 1 Ghz AMD Athlon, 512 MB RAM etc. etc.
I don't think that the hardware is related to the problem because I found it.

software: I used Win 98 (1st edition) and MS VC++ 6.0 to find/fix the bug in
Nethack 3.4.0.

comments: steps to crash: start nethackw.exe - start a game - select "fit to
sreen" in the map menue - rezize the map until it is very very small -> crash

win/win32/mhmap.c

index 08189a348f6053dcc8a7e635eb9555a743314299..fd7596cfcc2036d5516f12ef13cf56939116ad77 100644 (file)
@@ -92,8 +92,10 @@ void mswin_map_stretch(HWND hWnd, LPSIZE lpsz, BOOL redraw)
        
        /* set new screen tile size */
        data = (PNHMapWindow)GetWindowLong(hWnd, GWL_USERDATA);
-       data->xScrTile = (data->bFitToScreenMode? wnd_size.cx : lpsz->cx) / COLNO;
-       data->yScrTile = (data->bFitToScreenMode? wnd_size.cy : lpsz->cy) / ROWNO;
+       data->xScrTile = 
+               max(1, (data->bFitToScreenMode? wnd_size.cx : lpsz->cx) / COLNO);
+       data->yScrTile = 
+               max(1, (data->bFitToScreenMode? wnd_size.cy : lpsz->cy) / ROWNO);
 
        /* set map origin point */
        data->map_orig.x = max(0, client_rt.left + (wnd_size.cx - data->xScrTile*COLNO)/2 );