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:
Philippe Saint-Pierre
2011-02-23 01:08:25 +00:00
parent 41e4f0903d
commit 8d779aa8df
8 changed files with 25 additions and 19 deletions
+5 -3
View File
@@ -19,7 +19,7 @@ entry_ref helpFileRef;
bool helpFileWasFound = false;
void
size_to_string(off_t byteCount, char* name)
size_to_string(off_t byteCount, char* name, int maxLength)
{
struct {
off_t limit;
@@ -37,13 +37,15 @@ size_to_string(off_t byteCount, char* name)
};
if (byteCount < 1024) {
sprintf(name, B_TRANSLATE("%lld bytes"), byteCount);
snprintf(name, maxLength, B_TRANSLATE("%lld bytes"),
byteCount);
} else {
int i = 0;
while (byteCount >= scale[i].limit)
i++;
sprintf(name, scale[i].format, byteCount / scale[i].divisor);
snprintf(name, maxLength, scale[i].format,
byteCount / scale[i].divisor);
}
}
+1 -1
View File
@@ -70,7 +70,7 @@ extern bool helpFileWasFound;
#define deg2rad(x) (2.0 * M_PI * (x) / 360.0)
#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
+4 -3
View File
@@ -77,12 +77,13 @@ InfoWin::InfoWin(BPoint p, FileInfo *f, BWindow* parent)
// Size
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) {
// This is a directory.
char str[64];
sprintf(str, B_TRANSLATE(" in %d files"), f->count);
strcat(name, str);
snprintf(str, sizeof(str), B_TRANSLATE(" in %d files"),
f->count);
strlcat(name, str, sizeof(name));
}
info.push_back(Item(B_TRANSLATE_MARK("Size"), name));
+2 -1
View File
@@ -205,6 +205,7 @@ PieView::MessageReceived(BMessage* message)
fOutdated = true;
Invalidate();
}
break;
}
default:
@@ -494,7 +495,7 @@ PieView::_DrawDirectory(BRect b, FileInfo* info, float parentSpan,
// Show total volume capacity.
char label[B_PATH_NAME_LENGTH];
size_to_string(volCapacity, label);
size_to_string(volCapacity, label, sizeof(label));
SetHighColor(kPieBGColor);
SetDrawingMode(B_OP_OVER);
DrawString(label, BPoint(cx - StringWidth(label) / 2.0,
+1 -1
View File
@@ -102,7 +102,7 @@ Scanner::MessageReceived(BMessage* message)
BMessage msg(kOutdatedMsg);
fListener.SendMessage(&msg);
}
break;
}
default:
+3 -3
View File
@@ -79,7 +79,7 @@ FileInfo::Type() const
char mimeStr[B_MIME_TYPE_LENGTH] = { '\0' };
if (parent == NULL) {
// This is the volume's root directory; treat it as a volume type.
strcpy(mimeStr, kVolumeType);
strlcpy(mimeStr, kVolumeType, sizeof(mimeStr));
} else {
// Get the MIME type from the registrar.
BNode node(&ref);
@@ -93,14 +93,14 @@ FileInfo::Type() const
// BFS volumes (e.g., CDFS volumes return B_BAD_VALUE).
//nodeInfo.SetType(kDirType);
}
strcpy(mimeStr, kDirType);
strlcpy(mimeStr, kDirType, sizeof(mimeStr));
}
}
}
}
if (strlen(mimeStr) == 0)
strcpy(mimeStr, kFileType);
strlcpy(mimeStr, kFileType, sizeof(mimeStr));
return new BMimeType(mimeStr);
}
+9 -6
View File
@@ -44,16 +44,19 @@ StatusView::StatusView()
B_SIZE_UNSET));
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->SetExplicitMinSize(BSize(StringWidth(testLabel), B_SIZE_UNSET));
fCountView->SetExplicitMinSize(BSize(StringWidth(testLabel),
B_SIZE_UNSET));
fCountView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
fPathView = new BStringView(NULL, kEmptyStr);
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));
@@ -137,13 +140,13 @@ StatusView::ShowInfo(const FileInfo* info)
fPathView->SetText(pathLabel.String());
char label[B_PATH_NAME_LENGTH];
size_to_string(info->size, label);
size_to_string(info->size, label, sizeof(label));
fSizeView->SetText(label);
if (info->count > 0) {
char label[256];
sprintf(label, (info->count == 1) ? B_TRANSLATE("%d file") :
B_TRANSLATE("%d files"), info->count);
snprintf(label, sizeof(label), (info->count == 1) ?
B_TRANSLATE("%d file") : B_TRANSLATE("%d files"), info->count);
fCountView->SetText(label);
} else {
fCountView->SetText(kEmptyStr);
-1
View File
@@ -69,7 +69,6 @@ VolumeView::SetPath(BPath path)
void
VolumeView::MessageReceived(BMessage* msg)
{
msg->PrintToStream();
switch(msg->what) {
case kBtnRescan:
fPieView->MessageReceived(msg);