mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
remove default constructors; reword some errors; skip check is there is enough free space
This commit is contained in:
parent
36c816c693
commit
9068b28d28
|
@ -42,19 +42,12 @@ absl::Status LibPNGMain(const std::string& infile, const std::string& outfile) {
|
|||
|
||||
image.mutable_data()->format = PNG_FORMAT_RGBA;
|
||||
|
||||
auto buffer = malloc(PNG_IMAGE_SIZE(*image.mutable_data()));
|
||||
if (!buffer) {
|
||||
SAPI_RETURN_IF_ERROR(api.png_image_free(image.PtrBoth()));
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
sapi::v::Array<uint8_t> buffer_(PNG_IMAGE_SIZE(*image.mutable_data()));
|
||||
sapi::v::Array<uint8_t> buffer(PNG_IMAGE_SIZE(*image.mutable_data()));
|
||||
|
||||
sapi::v::NullPtr null = sapi::v::NullPtr();
|
||||
SAPI_ASSIGN_OR_RETURN(result,
|
||||
api.png_image_finish_read(image.PtrBoth(), &null,
|
||||
buffer_.PtrBoth(), 0, &null));
|
||||
buffer.PtrBoth(), 0, &null));
|
||||
if (!result) {
|
||||
return absl::InternalError(
|
||||
absl::StrCat("finish read error: ", image.mutable_data()->message));
|
||||
|
@ -62,7 +55,7 @@ absl::Status LibPNGMain(const std::string& infile, const std::string& outfile) {
|
|||
|
||||
SAPI_ASSIGN_OR_RETURN(result, api.png_image_write_to_file(
|
||||
image.PtrBoth(), outfile_var.PtrBefore(), 0,
|
||||
buffer_.PtrBoth(), 0, &null));
|
||||
buffer.PtrBoth(), 0, &null));
|
||||
if (!result) {
|
||||
return absl::InternalError(
|
||||
absl::StrCat("write error: ", image.mutable_data()->message));
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
#include "../tests/libpng.h" // NOLINT(build/include)
|
||||
|
||||
struct Data {
|
||||
Data() {}
|
||||
|
||||
int width;
|
||||
int height;
|
||||
uint8_t color_type;
|
||||
|
|
|
@ -61,4 +61,3 @@ class LibPNGSapiSandbox : public LibPNGSandbox {
|
|||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ TEST(SandboxTest, ReadWrite) {
|
|||
absl::StatusOr<int> status_or_int = api.png_image_begin_read_from_file(
|
||||
image.PtrBoth(), infile_var.PtrBefore());
|
||||
ASSERT_THAT(status_or_int, IsOk())
|
||||
<< "png_image_begin_read_from_file fatal error";
|
||||
<< "fatal error when invoking png_image_begin_read_from_file";
|
||||
ASSERT_THAT(status_or_int.value(), IsTrue())
|
||||
<< "png_image_begin_read_from_file failed: "
|
||||
<< image.mutable_data()->message;
|
||||
|
@ -63,11 +63,12 @@ TEST(SandboxTest, ReadWrite) {
|
|||
ASSERT_THAT(image.mutable_data()->version, Eq(PNG_IMAGE_VERSION))
|
||||
<< "image version changed";
|
||||
|
||||
sapi::v::Array<uint8_t> buffer_(PNG_IMAGE_SIZE(*image.mutable_data()));
|
||||
sapi::v::Array<uint8_t> buffer(PNG_IMAGE_SIZE(*image.mutable_data()));
|
||||
sapi::v::NullPtr null = sapi::v::NullPtr();
|
||||
status_or_int = api.png_image_finish_read(image.PtrBoth(), &null,
|
||||
buffer_.PtrBoth(), 0, &null);
|
||||
ASSERT_THAT(status_or_int, IsOk()) << "png_image_finish_read fatal error";
|
||||
buffer.PtrBoth(), 0, &null);
|
||||
ASSERT_THAT(status_or_int, IsOk())
|
||||
<< "fatal error when invoking png_image_finish_read";
|
||||
ASSERT_THAT(status_or_int.value(), IsTrue())
|
||||
<< "png_image_finish_read failed: " << image.mutable_data()->message;
|
||||
ASSERT_THAT(image.mutable_data()->version, Eq(PNG_IMAGE_VERSION))
|
||||
|
@ -76,8 +77,9 @@ TEST(SandboxTest, ReadWrite) {
|
|||
<< "image format changed";
|
||||
|
||||
status_or_int = api.png_image_write_to_file(
|
||||
image.PtrBoth(), outfile_var.PtrBefore(), 0, buffer_.PtrBoth(), 0, &null);
|
||||
ASSERT_THAT(status_or_int, IsOk()) << "png_image_write_to_file fatal error";
|
||||
image.PtrBoth(), outfile_var.PtrBefore(), 0, buffer.PtrBoth(), 0, &null);
|
||||
ASSERT_THAT(status_or_int, IsOk())
|
||||
<< "fatal error when invoking png_image_write_to_file";
|
||||
ASSERT_THAT(status_or_int.value(), IsTrue())
|
||||
<< "png_image_finish_read failed: " << image.mutable_data()->message;
|
||||
ASSERT_THAT(image.mutable_data()->version, Eq(PNG_IMAGE_VERSION))
|
||||
|
|
|
@ -32,8 +32,6 @@ using ::testing::IsTrue;
|
|||
using ::testing::NotNull;
|
||||
|
||||
struct Data {
|
||||
Data() {}
|
||||
|
||||
int width;
|
||||
int height;
|
||||
uint8_t color_type;
|
||||
|
|
Loading…
Reference in New Issue
Block a user