[haiku-commits] haiku: hrev44851 - src/apps/deskbar

  • From: jscipione@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 17 Nov 2012 01:53:48 +0100 (CET)

hrev44851 adds 1 changeset to branch 'master'
old head: debbd7bd8a94b4a35d35e395f09d1eda39da6605
new head: ec469b21a0d02bec481fcac04b15d7724b530ebc
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=ec469b2+^debbd7b

----------------------------------------------------------------------------

ec469b2: Refactor code from previous commit.
  
  * Check if offset is actually an error code and attempt to compensate
    At the very least don't use it as an offset (would be bad).
  * Write to the output string directly instead of copying a temp string.
  * Add a ToDo to check if day of week should go after time for locale
  * Replace hardcoded 64 in GetCurrentDate().

                                     [ John Scipione <jscipione@xxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev44851
Commit:      ec469b21a0d02bec481fcac04b15d7724b530ebc
URL:         http://cgit.haiku-os.org/haiku/commit/?id=ec469b2
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Sat Nov 17 00:48:46 2012 UTC

----------------------------------------------------------------------------

1 file changed, 14 insertions(+), 10 deletions(-)
src/apps/deskbar/TimeView.cpp | 24 ++++++++++++++----------

----------------------------------------------------------------------------

diff --git a/src/apps/deskbar/TimeView.cpp b/src/apps/deskbar/TimeView.cpp
index 519c0ea..8f8ee22 100644
--- a/src/apps/deskbar/TimeView.cpp
+++ b/src/apps/deskbar/TimeView.cpp
@@ -384,31 +384,35 @@ TTimeView::ShowCalendar(BPoint where)
 void
 TTimeView::GetCurrentTime()
 {
-       char tmp[sizeof(fCurrentTimeStr)];
        ssize_t offset = 0;
 
-       if (fShowSeconds) {
-               fLocale.FormatTime(tmp, sizeof(fCurrentTimeStr), fCurrentTime,
-                       B_MEDIUM_TIME_FORMAT);
-       } else {
-               fLocale.FormatTime(tmp, sizeof(fCurrentTimeStr), fCurrentTime,
-                       B_SHORT_TIME_FORMAT);
-       }
+       // ToDo: Check to see if we should write day of week after time for 
locale
 
        if (fShowDayOfWeek) {
                BString timeFormat("eee ");
                offset = fLocale.FormatTime(fCurrentTimeStr, 
sizeof(fCurrentTimeStr),
                        fCurrentTime, timeFormat);
+
+               if (offset < 0) {
+                       // error occured, attempt to overwrite with current time
+                       // (this should not ever happen)
+                       fLocale.FormatTime(fCurrentTimeStr, 
sizeof(fCurrentTimeStr),
+                               fCurrentTime,
+                               fShowSeconds ? B_MEDIUM_TIME_FORMAT : 
B_SHORT_TIME_FORMAT);
+                       return;
+               }
        }
 
-       strlcpy(fCurrentTimeStr + offset, tmp, sizeof(fCurrentTimeStr) - 
offset);
+       fLocale.FormatTime(fCurrentTimeStr + offset,
+               sizeof(fCurrentTimeStr) - offset, fCurrentTime,
+               fShowSeconds ? B_MEDIUM_TIME_FORMAT : B_SHORT_TIME_FORMAT);
 }
 
 
 void
 TTimeView::GetCurrentDate()
 {
-       char tmp[64];
+       char tmp[sizeof(fCurrentTimeStr)];
 
        fLocale.FormatDate(tmp, sizeof(fCurrentDateStr), fCurrentTime,
                B_FULL_DATE_FORMAT);


Other related posts:

  • » [haiku-commits] haiku: hrev44851 - src/apps/deskbar - jscipione