mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 18:17:45 +00:00
Refactor: Expose const_cast by removing ByteBuffer::warp(const void*, size_t)
This function did a const_cast internally which made the call side look "safe". This method is removed completely and call sites are replaced with ByteBuffer::wrap(const_cast<void*>(data), size) which makes the behaviour obvious.
This commit is contained in:
parent
ac9f6fd1f8
commit
b3d1a05261
15 changed files with 42 additions and 36 deletions
|
@ -1104,7 +1104,7 @@ static bool decode_bmp_pixel_data(BMPLoadingContext& context)
|
|||
return false;
|
||||
}
|
||||
|
||||
auto buffer = ByteBuffer::wrap(context.data + context.data_offset, context.data_size);
|
||||
auto buffer = ByteBuffer::wrap(const_cast<u8*>(context.data + context.data_offset), context.data_size);
|
||||
|
||||
if (context.dib.info.compression == Compression::RLE4 || context.dib.info.compression == Compression::RLE8
|
||||
|| context.dib.info.compression == Compression::RLE24) {
|
||||
|
|
|
@ -345,7 +345,7 @@ bool load_gif_frame_descriptors(GIFLoadingContext& context)
|
|||
if (context.data_size < 32)
|
||||
return false;
|
||||
|
||||
auto buffer = ByteBuffer::wrap(context.data, context.data_size);
|
||||
auto buffer = ByteBuffer::wrap(const_cast<u8*>(context.data), context.data_size);
|
||||
BufferStream stream(buffer);
|
||||
|
||||
Optional<GIFFormat> format = decode_gif_header(stream);
|
||||
|
@ -546,7 +546,7 @@ GIFImageDecoderPlugin::GIFImageDecoderPlugin(const u8* data, size_t size)
|
|||
m_context->data_size = size;
|
||||
}
|
||||
|
||||
GIFImageDecoderPlugin::~GIFImageDecoderPlugin() {}
|
||||
GIFImageDecoderPlugin::~GIFImageDecoderPlugin() { }
|
||||
|
||||
IntSize GIFImageDecoderPlugin::size()
|
||||
{
|
||||
|
@ -591,7 +591,7 @@ bool GIFImageDecoderPlugin::set_nonvolatile()
|
|||
|
||||
bool GIFImageDecoderPlugin::sniff()
|
||||
{
|
||||
auto buffer = ByteBuffer::wrap(m_context->data, m_context->data_size);
|
||||
auto buffer = ByteBuffer::wrap(const_cast<u8*>(m_context->data), m_context->data_size);
|
||||
BufferStream stream(buffer);
|
||||
return decode_gif_header(stream).has_value();
|
||||
}
|
||||
|
|
|
@ -170,7 +170,7 @@ static size_t find_largest_image(const ICOLoadingContext& context)
|
|||
size_t max_area = 0;
|
||||
size_t index = 0;
|
||||
size_t largest_index = 0;
|
||||
for(const auto& desc : context.images) {
|
||||
for (const auto& desc : context.images) {
|
||||
if (desc.width * desc.height > max_area) {
|
||||
max_area = desc.width * desc.height;
|
||||
largest_index = index;
|
||||
|
@ -182,7 +182,7 @@ static size_t find_largest_image(const ICOLoadingContext& context)
|
|||
|
||||
static bool load_ico_directory(ICOLoadingContext& context)
|
||||
{
|
||||
auto buffer = ByteBuffer::wrap(context.data, context.data_size);
|
||||
auto buffer = ByteBuffer::wrap(const_cast<u8*>(context.data), context.data_size);
|
||||
auto stream = BufferStream(buffer);
|
||||
auto image_count = decode_ico_header(stream);
|
||||
if (!image_count.has_value() || image_count.value() == 0) {
|
||||
|
@ -280,7 +280,7 @@ static bool load_ico_bmp(ICOLoadingContext& context, ImageDescriptor& desc)
|
|||
}
|
||||
|
||||
// Mask is 1bpp, and each row must be 4-byte aligned
|
||||
size_t mask_row_len = align_up_to(align_up_to(desc.width, 8)/8, 4);
|
||||
size_t mask_row_len = align_up_to(align_up_to(desc.width, 8) / 8, 4);
|
||||
size_t required_len = desc.height * (desc.width * sizeof(BMP_ARGB) + mask_row_len);
|
||||
size_t available_len = desc.size - sizeof(info);
|
||||
if (required_len > available_len) {
|
||||
|
@ -408,7 +408,7 @@ bool ICOImageDecoderPlugin::set_nonvolatile()
|
|||
|
||||
bool ICOImageDecoderPlugin::sniff()
|
||||
{
|
||||
auto buffer = ByteBuffer::wrap(m_context->data, m_context->data_size);
|
||||
auto buffer = ByteBuffer::wrap(const_cast<u8*>(m_context->data), m_context->data_size);
|
||||
BufferStream stream(buffer);
|
||||
return decode_ico_header(stream).has_value();
|
||||
}
|
||||
|
|
|
@ -1146,7 +1146,7 @@ static bool scan_huffman_stream(BufferStream& stream, JPGLoadingContext& context
|
|||
|
||||
static bool decode_jpg(JPGLoadingContext& context)
|
||||
{
|
||||
ByteBuffer buffer = ByteBuffer::wrap(context.data, context.data_size);
|
||||
ByteBuffer buffer = ByteBuffer::wrap(const_cast<u8*>(context.data), context.data_size);
|
||||
BufferStream stream(buffer);
|
||||
if (!parse_header(stream, context))
|
||||
return false;
|
||||
|
|
|
@ -166,7 +166,7 @@ public:
|
|||
{
|
||||
if (m_size_remaining < count)
|
||||
return false;
|
||||
buffer = ByteBuffer::wrap(m_data_ptr, count);
|
||||
buffer = ByteBuffer::wrap(const_cast<u8*>(m_data_ptr), count);
|
||||
m_data_ptr += count;
|
||||
m_size_remaining -= count;
|
||||
return true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue