print addons: remove invalid use of auto_ptr

GCC 13 warns that the use of auto_ptr on an array can lead to undefined
behavior, because auto_ptr will use `delete` instead of `delete[]`.

Replaced the use with `std::vector` instead. Since the `data()` member was only
introduced in C++11, the solution uses the [] operator instead to get the
address of the beginning of the array.

Change-Id: Ib457580eedb03338a454fb96b27602c3830c1634
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6644
Reviewed-by: Adrien Destugues <[email protected]>
Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
Niels Sascha Reedijk
2023-06-28 07:11:17 +00:00
committed by Adrien Destugues
parent 1f2e9ca260
commit fdc8b001a9
5 changed files with 100 additions and 112 deletions
@@ -6,7 +6,7 @@
#include "Lips3.h"
#include <memory>
#include <vector>
#include <Alert.h>
#include <Bitmap.h>
@@ -162,13 +162,10 @@ LIPS3Driver::NextBand(BBitmap* bitmap, BPoint* offset)
int compressedSize;
const uchar* buffer;
uchar* in_buffer = new uchar[in_size];
uchar* out_buffer = new uchar[out_size];
std::vector<uchar> in_buffer(in_size);
std::vector<uchar> out_buffer(out_size);
auto_ptr<uchar> _in_buffer (in_buffer);
auto_ptr<uchar> _out_buffer(out_buffer);
uchar* ptr2 = static_cast<uchar*>(in_buffer);
uchar* ptr2 = &in_buffer[0];
DBGMSG(("move\n"));
@@ -181,12 +178,12 @@ LIPS3Driver::NextBand(BBitmap* bitmap, BPoint* offset)
y++;
}
compressedSize = compress3(out_buffer, in_buffer, in_size);
compressedSize = compress3(&out_buffer[0], &in_buffer[0], in_size);
if (compressedSize < in_size) {
compressionMethod = 9;
// compress3
buffer = out_buffer;
buffer = &out_buffer[0];
} else if (compressedSize > out_size) {
BAlert* alert = new BAlert("memory overrun!!!", "warning",
"OK");
@@ -195,7 +192,7 @@ LIPS3Driver::NextBand(BBitmap* bitmap, BPoint* offset)
return false;
} else {
compressionMethod = 0;
buffer = in_buffer;
buffer = &in_buffer[0];
compressedSize = in_size;
}
@@ -6,7 +6,7 @@
#include "Lips4Cap.h"
#include <memory>
#include <vector>
#include <Alert.h>
#include <Bitmap.h>
@@ -172,13 +172,10 @@ LIPS4Driver::NextBand(BBitmap* bitmap, BPoint* offset)
int compressed_size;
const uchar* buffer;
uchar* in_buffer = new uchar[in_size];
uchar* out_buffer = new uchar[out_size];
std::vector<uchar> in_buffer(in_size);
std::vector<uchar> out_buffer(out_size);
auto_ptr<uchar> _in_buffer (in_buffer);
auto_ptr<uchar> _out_buffer(out_buffer);
uchar* ptr2 = static_cast<uchar *>(in_buffer);
uchar* ptr2 = &in_buffer[0];
DBGMSG(("move\n"));
@@ -193,11 +190,11 @@ LIPS4Driver::NextBand(BBitmap* bitmap, BPoint* offset)
DBGMSG(("PackBits\n"));
compressed_size = pack_bits(out_buffer, in_buffer, in_size);
compressed_size = pack_bits(&out_buffer[0], &in_buffer[0], in_size);
if (compressed_size < in_size) {
compression_method = 11;
buffer = out_buffer;
buffer = &out_buffer[0];
} else if (compressed_size > out_size) {
BAlert* alert = new BAlert("memory overrun!!!", "warning", "OK");
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
@@ -205,7 +202,7 @@ LIPS4Driver::NextBand(BBitmap* bitmap, BPoint* offset)
return false;
} else {
compression_method = 0;
buffer = in_buffer;
buffer = &in_buffer[0];
compressed_size = in_size;
}
+7 -10
View File
@@ -7,7 +7,7 @@
#include "PCL5.h"
#include <memory>
#include <vector>
#include <Alert.h>
#include <Bitmap.h>
@@ -148,11 +148,8 @@ PCL5Driver::NextBand(BBitmap* bitmap, BPoint* offset)
int compressedSize;
const uchar* buffer;
uchar* in_buffer = new uchar[in_size];
uchar* out_buffer = new uchar[out_size];
auto_ptr<uchar> _in_buffer (in_buffer);
auto_ptr<uchar> _out_buffer(out_buffer);
std::vector<uchar> in_buffer(in_size);
std::vector<uchar> out_buffer(out_size);
DBGMSG(("move\n"));
@@ -171,17 +168,17 @@ PCL5Driver::NextBand(BBitmap* bitmap, BPoint* offset)
for (int plane = 0; plane < num_planes; plane ++) {
fHalftone->Dither(in_buffer, ptr, x, y, width);
fHalftone->Dither(&in_buffer[0], ptr, x, y, width);
compressedSize = pack_bits(out_buffer, in_buffer, in_size);
compressedSize = pack_bits(&out_buffer[0], &in_buffer[0], in_size);
if (compressedSize + _BytesToEnterCompressionMethod(2)
< in_size + _BytesToEnterCompressionMethod(0)) {
compressionMethod = 2; // back bits
buffer = out_buffer;
buffer = &out_buffer[0];
} else {
compressionMethod = 0; // uncompressed
buffer = in_buffer;
buffer = &in_buffer[0];
compressedSize = in_size;
}
+8 -11
View File
@@ -8,7 +8,7 @@
#include "PS.h"
#include <memory.h>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
@@ -266,14 +266,11 @@ PSDriver::NextBand(BBitmap* bitmap, BPoint* offset)
int compressed_size;
const uchar* buffer;
uchar* in_buffer = new uchar[in_size];
std::vector<uchar> in_buffer(in_size);
// gray values
uchar* out_buffer = new uchar[out_size];
std::vector<uchar> out_buffer(out_size);
// gray values in hexadecimal
auto_ptr<uchar> _in_buffer(in_buffer);
auto_ptr<uchar> _out_buffer(out_buffer);
DBGMSG(("move\n"));
int size = color ? width * 3 : in_size;
@@ -281,7 +278,7 @@ PSDriver::NextBand(BBitmap* bitmap, BPoint* offset)
for (int i = rc.top; i <= rc.bottom; i++) {
if (color) {
uchar* out = out_buffer;
uchar* out = &out_buffer[0];
uchar* in = ptr;
for (int w = width; w > 0; w --) {
*out++ = ToHexDigit((in[2]) >> 4);
@@ -293,10 +290,10 @@ PSDriver::NextBand(BBitmap* bitmap, BPoint* offset)
in += 4;
}
} else {
fHalftone->Dither(in_buffer, ptr, x, y, width);
fHalftone->Dither(&in_buffer[0], ptr, x, y, width);
uchar* in = in_buffer;
uchar* out = out_buffer;
uchar* in = &in_buffer[0];
uchar* out = &out_buffer[0];
for (int w = in_size; w > 0; w --, in ++) {
*in = ~*in; // invert pixels
@@ -307,7 +304,7 @@ PSDriver::NextBand(BBitmap* bitmap, BPoint* offset)
{
compression_method = 0; // uncompressed
buffer = out_buffer;
buffer = &out_buffer[0];
compressed_size = out_size;
}