DiskUsage :
* add two missing break; (CID 3301, 3302)
* replace strcpy, strcat and sprintf by strlcpy, strlcat and snprintf
(CID 6804, 6805, 6806, 6807, 6808, 8962, 8963)
* remove a PrintToStream (left by accident for debugging purposes)
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40631 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -19,7 +19,7 @@ entry_ref helpFileRef;
|
|||||||
bool helpFileWasFound = false;
|
bool helpFileWasFound = false;
|
||||||
|
|
||||||
void
|
void
|
||||||
size_to_string(off_t byteCount, char* name)
|
size_to_string(off_t byteCount, char* name, int maxLength)
|
||||||
{
|
{
|
||||||
struct {
|
struct {
|
||||||
off_t limit;
|
off_t limit;
|
||||||
@@ -37,13 +37,15 @@ size_to_string(off_t byteCount, char* name)
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (byteCount < 1024) {
|
if (byteCount < 1024) {
|
||||||
sprintf(name, B_TRANSLATE("%lld bytes"), byteCount);
|
snprintf(name, maxLength, B_TRANSLATE("%lld bytes"),
|
||||||
|
byteCount);
|
||||||
} else {
|
} else {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (byteCount >= scale[i].limit)
|
while (byteCount >= scale[i].limit)
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
sprintf(name, scale[i].format, byteCount / scale[i].divisor);
|
snprintf(name, maxLength, scale[i].format,
|
||||||
|
byteCount / scale[i].divisor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ extern bool helpFileWasFound;
|
|||||||
#define deg2rad(x) (2.0 * M_PI * (x) / 360.0)
|
#define deg2rad(x) (2.0 * M_PI * (x) / 360.0)
|
||||||
#define rad2deg(x) (360.0 * (x) / (2.0 * M_PI))
|
#define rad2deg(x) (360.0 * (x) / (2.0 * M_PI))
|
||||||
|
|
||||||
void size_to_string(off_t byteCount, char* name);
|
void size_to_string(off_t byteCount, char* name, int maxLength);
|
||||||
|
|
||||||
|
|
||||||
#endif // DISKUSAGE_H
|
#endif // DISKUSAGE_H
|
||||||
|
|||||||
@@ -77,12 +77,13 @@ InfoWin::InfoWin(BPoint p, FileInfo *f, BWindow* parent)
|
|||||||
|
|
||||||
// Size
|
// Size
|
||||||
char name[B_PATH_NAME_LENGTH] = { 0 };
|
char name[B_PATH_NAME_LENGTH] = { 0 };
|
||||||
size_to_string(f->size, name);
|
size_to_string(f->size, name, sizeof(name));
|
||||||
if (f->count > 0) {
|
if (f->count > 0) {
|
||||||
// This is a directory.
|
// This is a directory.
|
||||||
char str[64];
|
char str[64];
|
||||||
sprintf(str, B_TRANSLATE(" in %d files"), f->count);
|
snprintf(str, sizeof(str), B_TRANSLATE(" in %d files"),
|
||||||
strcat(name, str);
|
f->count);
|
||||||
|
strlcat(name, str, sizeof(name));
|
||||||
}
|
}
|
||||||
info.push_back(Item(B_TRANSLATE_MARK("Size"), name));
|
info.push_back(Item(B_TRANSLATE_MARK("Size"), name));
|
||||||
|
|
||||||
|
|||||||
@@ -205,6 +205,7 @@ PieView::MessageReceived(BMessage* message)
|
|||||||
fOutdated = true;
|
fOutdated = true;
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -494,7 +495,7 @@ PieView::_DrawDirectory(BRect b, FileInfo* info, float parentSpan,
|
|||||||
|
|
||||||
// Show total volume capacity.
|
// Show total volume capacity.
|
||||||
char label[B_PATH_NAME_LENGTH];
|
char label[B_PATH_NAME_LENGTH];
|
||||||
size_to_string(volCapacity, label);
|
size_to_string(volCapacity, label, sizeof(label));
|
||||||
SetHighColor(kPieBGColor);
|
SetHighColor(kPieBGColor);
|
||||||
SetDrawingMode(B_OP_OVER);
|
SetDrawingMode(B_OP_OVER);
|
||||||
DrawString(label, BPoint(cx - StringWidth(label) / 2.0,
|
DrawString(label, BPoint(cx - StringWidth(label) / 2.0,
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ Scanner::MessageReceived(BMessage* message)
|
|||||||
BMessage msg(kOutdatedMsg);
|
BMessage msg(kOutdatedMsg);
|
||||||
fListener.SendMessage(&msg);
|
fListener.SendMessage(&msg);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ FileInfo::Type() const
|
|||||||
char mimeStr[B_MIME_TYPE_LENGTH] = { '\0' };
|
char mimeStr[B_MIME_TYPE_LENGTH] = { '\0' };
|
||||||
if (parent == NULL) {
|
if (parent == NULL) {
|
||||||
// This is the volume's root directory; treat it as a volume type.
|
// This is the volume's root directory; treat it as a volume type.
|
||||||
strcpy(mimeStr, kVolumeType);
|
strlcpy(mimeStr, kVolumeType, sizeof(mimeStr));
|
||||||
} else {
|
} else {
|
||||||
// Get the MIME type from the registrar.
|
// Get the MIME type from the registrar.
|
||||||
BNode node(&ref);
|
BNode node(&ref);
|
||||||
@@ -93,14 +93,14 @@ FileInfo::Type() const
|
|||||||
// BFS volumes (e.g., CDFS volumes return B_BAD_VALUE).
|
// BFS volumes (e.g., CDFS volumes return B_BAD_VALUE).
|
||||||
//nodeInfo.SetType(kDirType);
|
//nodeInfo.SetType(kDirType);
|
||||||
}
|
}
|
||||||
strcpy(mimeStr, kDirType);
|
strlcpy(mimeStr, kDirType, sizeof(mimeStr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(mimeStr) == 0)
|
if (strlen(mimeStr) == 0)
|
||||||
strcpy(mimeStr, kFileType);
|
strlcpy(mimeStr, kFileType, sizeof(mimeStr));
|
||||||
|
|
||||||
return new BMimeType(mimeStr);
|
return new BMimeType(mimeStr);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,16 +44,19 @@ StatusView::StatusView()
|
|||||||
B_SIZE_UNSET));
|
B_SIZE_UNSET));
|
||||||
|
|
||||||
char testLabel[256];
|
char testLabel[256];
|
||||||
sprintf(testLabel, B_TRANSLATE("%d files"), 999999);
|
snprintf(testLabel, sizeof(testLabel), B_TRANSLATE("%d files"),
|
||||||
|
999999);
|
||||||
|
|
||||||
fCountView = new BStringView(NULL, kEmptyStr);
|
fCountView = new BStringView(NULL, kEmptyStr);
|
||||||
fCountView->SetExplicitMinSize(BSize(StringWidth(testLabel), B_SIZE_UNSET));
|
fCountView->SetExplicitMinSize(BSize(StringWidth(testLabel),
|
||||||
|
B_SIZE_UNSET));
|
||||||
fCountView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
|
fCountView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
|
||||||
|
|
||||||
fPathView = new BStringView(NULL, kEmptyStr);
|
fPathView = new BStringView(NULL, kEmptyStr);
|
||||||
fPathView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
|
fPathView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
|
||||||
|
|
||||||
fRefreshBtn = new BButton(NULL, B_TRANSLATE("Scan"), new BMessage(kBtnRescan));
|
fRefreshBtn = new BButton(NULL, B_TRANSLATE("Scan"),
|
||||||
|
new BMessage(kBtnRescan));
|
||||||
|
|
||||||
fRefreshBtn->SetExplicitMaxSize(BSize(B_SIZE_UNSET, B_SIZE_UNLIMITED));
|
fRefreshBtn->SetExplicitMaxSize(BSize(B_SIZE_UNSET, B_SIZE_UNLIMITED));
|
||||||
|
|
||||||
@@ -137,13 +140,13 @@ StatusView::ShowInfo(const FileInfo* info)
|
|||||||
fPathView->SetText(pathLabel.String());
|
fPathView->SetText(pathLabel.String());
|
||||||
|
|
||||||
char label[B_PATH_NAME_LENGTH];
|
char label[B_PATH_NAME_LENGTH];
|
||||||
size_to_string(info->size, label);
|
size_to_string(info->size, label, sizeof(label));
|
||||||
fSizeView->SetText(label);
|
fSizeView->SetText(label);
|
||||||
|
|
||||||
if (info->count > 0) {
|
if (info->count > 0) {
|
||||||
char label[256];
|
char label[256];
|
||||||
sprintf(label, (info->count == 1) ? B_TRANSLATE("%d file") :
|
snprintf(label, sizeof(label), (info->count == 1) ?
|
||||||
B_TRANSLATE("%d files"), info->count);
|
B_TRANSLATE("%d file") : B_TRANSLATE("%d files"), info->count);
|
||||||
fCountView->SetText(label);
|
fCountView->SetText(label);
|
||||||
} else {
|
} else {
|
||||||
fCountView->SetText(kEmptyStr);
|
fCountView->SetText(kEmptyStr);
|
||||||
|
|||||||
@@ -69,7 +69,6 @@ VolumeView::SetPath(BPath path)
|
|||||||
void
|
void
|
||||||
VolumeView::MessageReceived(BMessage* msg)
|
VolumeView::MessageReceived(BMessage* msg)
|
||||||
{
|
{
|
||||||
msg->PrintToStream();
|
|
||||||
switch(msg->what) {
|
switch(msg->what) {
|
||||||
case kBtnRescan:
|
case kBtnRescan:
|
||||||
fPieView->MessageReceived(msg);
|
fPieView->MessageReceived(msg);
|
||||||
|
|||||||
Reference in New Issue
Block a user