* Puh, there was quite a confusion with variable names here, Axel.
Don't we have this "blah shadows a parameter" warning enabled? * data was leaked in the error code path when allocating the bitmaps failed. * I've added a check if the provided buffer even has the right size before copying the B_CMAP8 bitmap data into it. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27044 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+21
-16
@@ -20,6 +20,7 @@
|
|||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <AutoDeleter.h>
|
||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
#include <Drivers.h>
|
#include <Drivers.h>
|
||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
@@ -181,31 +182,35 @@ get_device_icon(const char *device, void *icon, int32 size)
|
|||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
uint8* data;
|
uint8* data;
|
||||||
size_t size;
|
size_t dataSize;
|
||||||
type_code type;
|
type_code type;
|
||||||
status_t status = get_device_icon(device, &data, &size, &type);
|
status_t status = get_device_icon(device, &data, &dataSize, &type);
|
||||||
if (status == B_OK) {
|
if (status == B_OK) {
|
||||||
BBitmap* icon = new(std::nothrow) BBitmap(
|
BBitmap* icon32 = new(std::nothrow) BBitmap(
|
||||||
BRect(0, 0, size - 1, size - 1), B_BITMAP_NO_SERVER_LINK,
|
BRect(0, 0, size - 1, size - 1), B_BITMAP_NO_SERVER_LINK,
|
||||||
B_RGBA32);
|
B_RGBA32);
|
||||||
BBitmap* target = new(std::nothrow) BBitmap(
|
BBitmap* icon8 = new(std::nothrow) BBitmap(
|
||||||
BRect(0, 0, size - 1, size - 1), B_BITMAP_NO_SERVER_LINK,
|
BRect(0, 0, size - 1, size - 1), B_BITMAP_NO_SERVER_LINK,
|
||||||
B_CMAP8);
|
B_CMAP8);
|
||||||
if (icon == NULL || icon->InitCheck() != B_OK || target == NULL
|
|
||||||
|| target->InitCheck() != B_OK) {
|
ArrayDeleter<uint8> dataDeleter(data);
|
||||||
delete icon;
|
ObjectDeleter<BBitmap> icon32Deleter(icon32);
|
||||||
delete target;
|
ObjectDeleter<BBitmap> icon8Deleter(icon8);
|
||||||
|
|
||||||
|
if (icon32 == NULL || icon32->InitCheck() != B_OK || icon8 == NULL
|
||||||
|
|| icon8->InitCheck() != B_OK) {
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
}
|
}
|
||||||
status = BIconUtils::GetVectorIcon(data, size, icon);
|
|
||||||
if (status == B_OK)
|
|
||||||
status = BIconUtils::ConvertToCMAP8(icon, target);
|
|
||||||
if (status == B_OK)
|
|
||||||
memcpy(icon, target->Bits(), target->BitsLength());
|
|
||||||
|
|
||||||
delete icon;
|
if (size < icon8->BitsLength())
|
||||||
delete target;
|
return B_BAD_VALUE;
|
||||||
delete[] data;
|
|
||||||
|
status = BIconUtils::GetVectorIcon(data, dataSize, icon32);
|
||||||
|
if (status == B_OK)
|
||||||
|
status = BIconUtils::ConvertToCMAP8(icon32, icon8);
|
||||||
|
if (status == B_OK)
|
||||||
|
memcpy(icon, icon8->Bits(), icon8->BitsLength());
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
return errno;
|
return errno;
|
||||||
|
|||||||
Reference in New Issue
Block a user