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
This commit is contained in:
parent
11b3c08b53
commit
136d40a890
@ -33,9 +33,11 @@ All rights reserved.
|
||||
*/
|
||||
|
||||
#include <Debug.h>
|
||||
#include <malloc.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <Bitmap.h>
|
||||
#include <Font.h>
|
||||
#include <Region.h>
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user