Nikolay Sivov : comctl32/monthcal: Make sure set today date is valid before using it (Valgrind).

Alexandre Julliard julliard at winehq.org
Tue Jan 2 15:01:23 CST 2018


Module: wine
Branch: stable
Commit: 3097566cde988635d04ceafb048569ee0bfc62cd
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=3097566cde988635d04ceafb048569ee0bfc62cd

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Mon Aug 28 00:07:51 2017 +0300

comctl32/monthcal: Make sure set today date is valid before using it (Valgrind).

Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
(cherry picked from commit a56f49cdd5a3ec14d9c0c5e755f7e3edc4f0835b)
Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>

---

 dlls/comctl32/monthcal.c | 37 +++++++++++++++++++++++--------------
 1 file changed, 23 insertions(+), 14 deletions(-)

diff --git a/dlls/comctl32/monthcal.c b/dlls/comctl32/monthcal.c
index 6a10860..4a9a81e 100644
--- a/dlls/comctl32/monthcal.c
+++ b/dlls/comctl32/monthcal.c
@@ -257,10 +257,12 @@ static inline BOOL MONTHCAL_IsDateEqual(const SYSTEMTIME *first, const SYSTEMTIM
 /* make sure that date fields are valid */
 static BOOL MONTHCAL_ValidateDate(const SYSTEMTIME *time)
 {
-  if(time->wMonth < 1 || time->wMonth > 12 ) return FALSE;
-  if(time->wDay > MONTHCAL_MonthLength(time->wMonth, time->wYear)) return FALSE;
+    if (time->wMonth < 1 || time->wMonth > 12 )
+        return FALSE;
+    if (time->wDay == 0 || time->wDay > MONTHCAL_MonthLength(time->wMonth, time->wYear))
+        return FALSE;
 
-  return TRUE;
+    return TRUE;
 }
 
 /* Copies timestamp part only.
@@ -1738,21 +1740,28 @@ MONTHCAL_GetToday(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *today)
 static BOOL
 MONTHCAL_UpdateToday(MONTHCAL_INFO *infoPtr, const SYSTEMTIME *today)
 {
-  RECT new_r, old_r;
+    RECT rect;
+
+    if (MONTHCAL_IsDateEqual(today, &infoPtr->todaysDate))
+        return FALSE;
 
-  if(MONTHCAL_IsDateEqual(today, &infoPtr->todaysDate)) return FALSE;
+    /* Invalidate old and new today day rectangle, and today label. */
+    if (MONTHCAL_ValidateDate(&infoPtr->todaysDate))
+    {
+        MONTHCAL_GetDayRect(infoPtr, &infoPtr->todaysDate, &rect, -1);
+        InvalidateRect(infoPtr->hwndSelf, &rect, FALSE);
+    }
 
-  MONTHCAL_GetDayRect(infoPtr, &infoPtr->todaysDate, &old_r, -1);
-  MONTHCAL_GetDayRect(infoPtr, today, &new_r, -1);
+    if (MONTHCAL_ValidateDate(today))
+    {
+        MONTHCAL_GetDayRect(infoPtr, today, &rect, -1);
+        InvalidateRect(infoPtr->hwndSelf, &rect, FALSE);
+    }
 
-  infoPtr->todaysDate = *today;
+    infoPtr->todaysDate = *today;
 
-  /* only two days need redrawing */
-  InvalidateRect(infoPtr->hwndSelf, &old_r, FALSE);
-  InvalidateRect(infoPtr->hwndSelf, &new_r, FALSE);
-  /* and today label */
-  InvalidateRect(infoPtr->hwndSelf, &infoPtr->todayrect, FALSE);
-  return TRUE;
+    InvalidateRect(infoPtr->hwndSelf, &infoPtr->todayrect, FALSE);
+    return TRUE;
 }
 
 /* MCM_SETTODAT handler */




More information about the wine-cvs mailing list