Skip to content

Commit 30cb773

Browse files
committed
the write() function of a heif_writer may now return a NULL message when there is no error (#1493)
1 parent 8531ee0 commit 30cb773

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

libheif/api/libheif/heif.cc

+8-1
Original file line numberDiff line numberDiff line change
@@ -2663,7 +2663,14 @@ struct heif_error heif_context_write(struct heif_context* ctx,
26632663
const auto& data = swriter.get_data();
26642664
heif_error writer_error = writer->write(ctx, data.data(), data.size(), userdata);
26652665
if (!writer_error.message) {
2666-
return heif_error{heif_error_Usage_error, heif_suberror_Null_pointer_argument, "heif_writer callback returned a null error text"};
2666+
// It is now allowed to return a NULL error message on success. It will be replaced by "Success". An error message is still required when there is an error.
2667+
if (writer_error.code == heif_error_Ok) {
2668+
writer_error.message = Error::kSuccess;
2669+
return writer_error;
2670+
}
2671+
else {
2672+
return heif_error{heif_error_Usage_error, heif_suberror_Null_pointer_argument, "heif_writer callback returned a null error text"};
2673+
}
26672674
}
26682675
else {
26692676
return writer_error;

libheif/api/libheif/heif.h

+2
Original file line numberDiff line numberDiff line change
@@ -2059,6 +2059,8 @@ struct heif_writer
20592059
int writer_api_version;
20602060

20612061
// --- version 1 functions ---
2062+
2063+
// On success, the returned heif_error may have a NULL message. It will automatically be replaced with a "Success" string.
20622064
struct heif_error (* write)(struct heif_context* ctx, // TODO: why do we need this parameter?
20632065
const void* data,
20642066
size_t size,

0 commit comments

Comments
 (0)