comctl32/trackbar: Protect from negative tic count in recalculation helper.
authorNikolay Sivov <bunglehead@gmail.com>
Thu, 17 Sep 2009 22:18:48 +0000 (02:18 +0400)
committerAlexandre Julliard <julliard@winehq.org>
Fri, 18 Sep 2009 13:56:09 +0000 (08:56 -0500)
Fix for regression introduced in 42c83b9dc7b5094384e718926eddd4b297c7bbae

dlls/comctl32/tests/trackbar.c
dlls/comctl32/trackbar.c

index d790206f479d36c4c66c01dae607114d0d88d01a..22fbbfe40a2ad97bacdde3fad9b59343877c8e2d 100644 (file)
@@ -785,22 +785,41 @@ static void test_tic_settings(HWND hWndTrackbar){
     /* test TBM_SETTICFREQ */
     SendMessage(hWndTrackbar, TBM_SETRANGE, TRUE, MAKELONG(0, 10));
     SendMessage(hWndTrackbar, TBM_SETTICFREQ, 2, 0);
-    r = SendMessage(hWndTrackbar, TBM_GETNUMTICS, 0,0);
+    r = SendMessage(hWndTrackbar, TBM_GETNUMTICS, 0, 0);
     expect(6, r);
     SendMessage(hWndTrackbar, TBM_SETTICFREQ, 5, 0);
-    r = SendMessage(hWndTrackbar, TBM_GETNUMTICS, 0,0);
+    r = SendMessage(hWndTrackbar, TBM_GETNUMTICS, 0, 0);
     expect(3, r);
     SendMessage(hWndTrackbar, TBM_SETTICFREQ, 15, 0);
-    r = SendMessage(hWndTrackbar, TBM_GETNUMTICS, 0,0);
+    r = SendMessage(hWndTrackbar, TBM_GETNUMTICS, 0, 0);
     expect(2, r);
 
     /* test TBM_GETNUMTICS */
     /* since TIC FREQ is 15, there should be only 2 tics now */
-    r = SendMessage(hWndTrackbar, TBM_GETNUMTICS, 0,0);
+    r = SendMessage(hWndTrackbar, TBM_GETNUMTICS, 0, 0);
     expect(2, r);
 
     ok_sequence(sequences, TRACKBAR_SEQ_INDEX, tic_settings_test_seq, "tic settings test sequence", TRUE);
     ok_sequence(sequences, PARENT_SEQ_INDEX, parent_tic_settings_test_seq, "parent tic settings test sequence", TRUE);
+
+    /* range [0,0], freq = 1 */
+    SendMessage(hWndTrackbar, TBM_SETRANGEMAX, TRUE, 0);
+    SendMessage(hWndTrackbar, TBM_SETRANGEMIN, TRUE, 0);
+    SendMessage(hWndTrackbar, TBM_SETTICFREQ, 1, 0);
+    r = SendMessage(hWndTrackbar, TBM_GETNUMTICS, 0, 0);
+    expect(2, r);
+    /* range [0,1], freq = 1 */
+    SendMessage(hWndTrackbar, TBM_SETRANGEMAX, TRUE, 1);
+    SendMessage(hWndTrackbar, TBM_SETRANGEMIN, TRUE, 0);
+    SendMessage(hWndTrackbar, TBM_SETTICFREQ, 1, 0);
+    r = SendMessage(hWndTrackbar, TBM_GETNUMTICS, 0, 0);
+    expect(2, r);
+    /* range [0,2], freq = 1 */
+    SendMessage(hWndTrackbar, TBM_SETRANGEMAX, TRUE, 2);
+    SendMessage(hWndTrackbar, TBM_SETRANGEMIN, TRUE, 0);
+    SendMessage(hWndTrackbar, TBM_SETTICFREQ, 1, 0);
+    r = SendMessage(hWndTrackbar, TBM_GETNUMTICS, 0, 0);
+    expect(3, r);
 }
 
 static void test_tic_placement(HWND hWndTrackbar){
index 88f1df10b0a71268f7a9e6bc8a0909f86b7c591b..5abc77fb8a47ac4f946452dd2b2c4170e148142b 100644 (file)
@@ -155,7 +155,7 @@ static void TRACKBAR_RecalculateTics (TRACKBAR_INFO *infoPtr)
     if (infoPtr->uTicFreq && infoPtr->lRangeMax >= infoPtr->lRangeMin) {
         nrTics=(infoPtr->lRangeMax - infoPtr->lRangeMin)/infoPtr->uTicFreq;
         /* don't add extra tic if there's no remainder */
-        if ((infoPtr->lRangeMax - infoPtr->lRangeMin) % infoPtr->uTicFreq == 0)
+        if (nrTics && ((infoPtr->lRangeMax - infoPtr->lRangeMin) % infoPtr->uTicFreq == 0))
           nrTics--;
     }
     else {