[haiku-commits] r40538 - haiku/trunk/src/preferences/time

  • From: zooey@xxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 16 Feb 2011 20:25:19 +0100 (CET)

Author: zooey
Date: 2011-02-16 20:25:19 +0100 (Wed, 16 Feb 2011)
New Revision: 40538
Changeset: http://dev.haiku-os.org/changeset/40538

Modified:
   haiku/trunk/src/preferences/time/DateTimeEdit.cpp
Log:
* fix out-of-bounds access to fFieldsPositions when drawing separator
  (found by running the preflet with debug heap and guard pages)
* avoid leaking of field- and field-position-arrays when fetching them
  via BLocale-method

Modified: haiku/trunk/src/preferences/time/DateTimeEdit.cpp
===================================================================
--- haiku/trunk/src/preferences/time/DateTimeEdit.cpp   2011-02-16 19:22:43 UTC 
(rev 40537)
+++ haiku/trunk/src/preferences/time/DateTimeEdit.cpp   2011-02-16 19:25:19 UTC 
(rev 40538)
@@ -100,7 +100,7 @@
        if (!section)
                return;
 
-       if (fFieldPositions == NULL || index * 2 + 1 > (uint32)fFieldPosCount)
+       if (fFieldPositions == NULL || index * 2 + 1 >= (uint32)fFieldPosCount)
                return;
 
        BRect bounds = section->Frame();
@@ -132,7 +132,7 @@
        if (!section)
                return;
 
-       if (fFieldPositions == NULL || index * 2 + 2 > (uint32)fFieldPosCount)
+       if (fFieldPositions == NULL || index * 2 + 2 >= (uint32)fFieldPosCount)
                return;
 
        BString field;
@@ -277,8 +277,18 @@
 TTimeEdit::_UpdateFields()
 {
        time_t time = fTime.Time_t();
+
+       if (fFieldPositions != NULL) {
+               free(fFieldPositions);
+               fFieldPositions = NULL;
+       }
        BLocale::Default()->FormatTime(&fText, fFieldPositions, fFieldPosCount,
                time, B_MEDIUM_TIME_FORMAT);
+
+       if (fFields != NULL) {
+               free(fFields);
+               fFields = NULL;
+       }
        BLocale::Default()->GetTimeFields(fFields, fFieldCount,
                B_MEDIUM_TIME_FORMAT);
 }
@@ -492,7 +502,7 @@
        if (!section)
                return;
 
-       if (fFieldPositions == NULL || index * 2 + 1 > (uint32)fFieldPosCount)
+       if (fFieldPositions == NULL || index * 2 + 1 >= (uint32)fFieldPosCount)
                return;
 
        SetLowColor(ViewColor());
@@ -525,7 +535,7 @@
        if (!section)
                return;
 
-       if (fFieldPositions == NULL || index * 2 + 2 > (uint32)fFieldPosCount)
+       if (fFieldPositions == NULL || index * 2 + 2 >= (uint32)fFieldPosCount)
                return;
 
        BString field;
@@ -677,8 +687,18 @@
 TDateEdit::_UpdateFields()
 {
        time_t time = BDateTime(fDate, BTime()).Time_t();
+
+       if (fFieldPositions != NULL) {
+               free(fFieldPositions);
+               fFieldPositions = NULL;
+       }
        BLocale::Default()->FormatDate(&fText, fFieldPositions, fFieldPosCount,
                time, B_SHORT_DATE_FORMAT);
+
+       if (fFields != NULL) {
+               free(fFields);
+               fFields = NULL;
+       }
        BLocale::Default()->GetDateFields(fFields, fFieldCount,
                B_SHORT_DATE_FORMAT);
 }


Other related posts:

  • » [haiku-commits] r40538 - haiku/trunk/src/preferences/time - zooey