You can't return a pointer to an array allocated on the stack. This fixes the uptime not being showed correctly.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13320 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini 2005-06-28 15:30:44 +00:00
parent 0c26ddbc29
commit 914c1a4528
1 changed files with 12 additions and 10 deletions

View File

@ -31,7 +31,7 @@
#define MOVE_INFO_VIEW 'mviv'
const char *UptimeToString(void);
static const char *UptimeToString(char string[], size_t size);
class AboutApp : public BApplication {
@ -235,7 +235,9 @@ AboutView::AboutView(const BRect &r)
fUptimeView = new BStringView(r, "uptimetext", "");
fInfoView->AddChild(fUptimeView);
fUptimeView->SetText(UptimeToString());
char uptimeString[255];
fUptimeView->SetText(UptimeToString(uptimeString, 255));
// Begin construction of the credits view
r = Bounds();
@ -442,7 +444,8 @@ AboutView::Draw(BRect update)
void
AboutView::Pulse(void)
{
fUptimeView->SetText(UptimeToString());
char uptime[255];
fUptimeView->SetText(UptimeToString(uptime, 255));
}
@ -463,10 +466,9 @@ AboutView::MessageReceived(BMessage *msg)
// #pragma mark -
const char *
UptimeToString(void)
static const char *
UptimeToString(char string[], size_t size)
{
char string[255];
int64 days, hours, minutes, seconds, remainder;
int64 systime = system_time();
@ -481,7 +483,7 @@ UptimeToString(void)
remainder = remainder % 60000000;
seconds = remainder / 1000000;
sprintf(string, "%lld days, %lld hours, %lld minutes, %lld seconds",
snprintf(string, size, "%lld days, %lld hours, %lld minutes, %lld seconds",
days, hours, minutes, seconds);
} else if (systime > 3600000000LL) {
hours = systime / 3600000000LL;
@ -491,17 +493,17 @@ UptimeToString(void)
remainder = remainder % 60000000;
seconds = remainder / 1000000;
sprintf(string, "%lld hours, %lld minutes, %lld seconds",
snprintf(string, size, "%lld hours, %lld minutes, %lld seconds",
hours, minutes, seconds);
} else if (systime > 60000000) {
minutes = systime / 60000000;
remainder = systime % 60000000;
seconds = remainder / 1000000;
sprintf(string, "%lld minutes, %lld seconds", minutes, seconds);
snprintf(string, size, "%lld minutes, %lld seconds", minutes, seconds);
} else {
seconds = systime / 1000000;
sprintf(string, "%lld seconds", seconds);
snprintf(string, size, "%lld seconds", seconds);
}
return string;