From 136d40a89025d81ea1f429148cd04334ee75b067 Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Thu, 18 Sep 2008 10:24:19 +0000 Subject: [PATCH] in case the passed name was NULL, the TeamMenuItem would set a NULL label, instead of passing the 'team n' string. Also use snprintf() to build said string, and change the code a bit. malloc.h > stdlib.h, and don't check for null before calling free() git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27617 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/deskbar/TeamMenuItem.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/apps/deskbar/TeamMenuItem.cpp b/src/apps/deskbar/TeamMenuItem.cpp index 3a15e0b264..43349e7764 100644 --- a/src/apps/deskbar/TeamMenuItem.cpp +++ b/src/apps/deskbar/TeamMenuItem.cpp @@ -33,9 +33,11 @@ All rights reserved. */ #include -#include + #include #include +#include + #include #include #include @@ -82,13 +84,14 @@ TTeamMenuItem::InitData(BList *team, BBitmap *icon, char *name, char *sig, fIcon = icon; fName = name; fSig = sig; - SetLabel(name); if (fName == NULL) { - char *tmp = (char *)malloc(32); - sprintf(tmp, "team %ld", (int32)team->ItemAt(0)); - fName = tmp; + char temp[32]; + snprintf(temp, sizeof(temp), "team %ld", (int32)team->ItemAt(0)); + fName = strdup(temp); } + SetLabel(fName); + BFont font(be_plain_font); fLabelWidth = ceilf(font.StringWidth(fName)); font_height fontHeight; @@ -419,8 +422,7 @@ TTeamMenuItem::DrawContentLabel() menu->DrawString(label); - if (truncLabel) - free(truncLabel); + free(truncLabel); }