* Use std::nothrow and check the bitmap/cursor allocations.

* CID 2500 and 2501: Check the BMessage::FindData() returns.
* Defensive programming: Take the bitmap/cursor BitsLength() into account when
  copying the data back.
* Some style cleanup, automatic whitespace cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39971 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Lotz
2010-12-28 01:19:47 +00:00
parent 83e36298a5
commit 25702ce874
+35 -12
View File
@@ -18,6 +18,8 @@
#include <String.h>
#include <File.h>
#include <new>
/*!
\brief Constructor
@@ -174,7 +176,7 @@ CursorSet::FindCursor(BCursorID which, BBitmap **cursor, BPoint *hotspot)
const void *buffer;
const char *tempstr;
int32 bufferLength;
BBitmap *bmp;
BBitmap *bitmap;
BPoint hotpt;
if (msg.FindString("class", &tempstr) != B_OK)
@@ -184,16 +186,25 @@ CursorSet::FindCursor(BCursorID which, BBitmap **cursor, BPoint *hotspot)
return B_ERROR;
if (strcmp(tempstr, "cursor") == 0) {
bmp = new BBitmap(msg.FindRect("_frame"),
bitmap = new(std::nothrow) BBitmap(msg.FindRect("_frame"),
(color_space)msg.FindInt32("_cspace"), true);
msg.FindData("_data", B_RAW_TYPE, (const void **)&buffer,
(ssize_t *)&bufferLength);
memcpy(bmp->Bits(), buffer, bufferLength);
if (bitmap == NULL)
return B_NO_MEMORY;
*cursor = bmp;
if (msg.FindData("_data", B_RAW_TYPE, (const void **)&buffer,
(ssize_t *)&bufferLength) != B_OK) {
delete bitmap;
return B_ERROR;
}
memcpy(bitmap->Bits(), buffer,
min_c(bufferLength, bitmap->BitsLength()));
*cursor = bitmap;
*hotspot = hotpt;
return B_OK;
}
return B_ERROR;
}
@@ -227,14 +238,22 @@ CursorSet::FindCursor(BCursorID which, ServerCursor **_cursor) const
return B_ERROR;
if (strcmp(className, "cursor") == 0) {
ServerCursor *cursor = new ServerCursor(msg.FindRect("_frame"),
(color_space)msg.FindInt32("_cspace"), 0, hotspot);
ServerCursor *cursor = new(std::nothrow) ServerCursor(
msg.FindRect("_frame"), (color_space)msg.FindInt32("_cspace"), 0,
hotspot);
if (cursor == NULL)
return B_NO_MEMORY;
const void *buffer;
int32 bufferLength;
msg.FindData("_data",B_RAW_TYPE, (const void **)&buffer,
(ssize_t *)&bufferLength);
memcpy(cursor->Bits(), buffer, bufferLength);
if (msg.FindData("_data", B_RAW_TYPE, (const void **)&buffer,
(ssize_t *)&bufferLength) != B_OK) {
delete cursor;
return B_ERROR;
}
memcpy(cursor->Bits(), buffer,
min_c(bufferLength, (ssize_t)cursor->BitsLength()));
*_cursor = cursor;
return B_OK;
@@ -361,7 +380,10 @@ CursorSet::_CursorDataToBitmap(uint8 *data)
// Now that we have all the setup, we're going to map (for now) the cursor
// to RGBA32. Eventually, there will be support for 16 and 8-bit depths
if (data) {
BBitmap *bmp = new BBitmap(BRect(0,0,15,15),B_RGBA32,0);
BBitmap *bmp = new(std::nothrow) BBitmap(BRect(0,0,15,15),B_RGBA32,0);
if (bmp == NULL)
return NULL;
uint32 black = 0xFF000000, white=0xFFFFFFFF, *bmppos;
uint16 *cursorpos, *maskpos, cursorflip, maskflip;
uint16 cursorval, maskval, powval;
@@ -392,6 +414,7 @@ CursorSet::_CursorDataToBitmap(uint8 *data)
& (maskval > 0 ? 0xFFFFFFFF : 0x00FFFFFF);
}
}
return bmp;
}