Make "uninitialized internal buffers" explicit

This commit is contained in:
Nigel Tao committed 2019-02-16 14:02:32 +11:00
1 parent 8ff151ce2d
commit b41f121d20
11 files changed
+238 -76

No files matched your search

@@ -72,6 +72,32 @@
// has already been set to all zeroes.
#define WUFFS_INITIALIZE__ALREADY_ZEROED ((uint32_t)0x00000001)
// WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED means that, absent
// WUFFS_INITIALIZE__ALREADY_ZEROED, only some of the "self" receiver struct
// value will be set to all zeroes. Internal buffers, which tend to be a large
// proportion of the struct's size, will be left uninitialized. Internal means
// that the buffer is contained by the receiver struct, as opposed to being
// passed as a separately allocated "work buffer".
//
// With or without this bit set, the Wuffs compiler still enforces that no
// reads or writes will overflow internal buffers' bounds. Even with this bit
// set, the Wuffs standard library also considers reading from an uninitialized
// buffer to be a bug, and strives to never do so, but unlike buffer overflows,
// it is not a bug class that the Wuffs compiler eliminates.
//
// For those paranoid about security, leave this bit unset, so that
// wuffs_foo__bar__initialize will initialize the entire struct value to zeroes
// (unless WUFFS_INITIALIZE__ALREADY_ZEROED is set).
//
// Setting this bit gives a small absolute improvement on micro-benchmarks, but
// this can be a large relative effect, up to 2x faster, when the actual work
// to be done is also small, such as decompressing small input. See git commit
// 438fc105 "Move some struct fields to private_data" for some numbers and a
// discussion, noting that its commit message was written before this
// WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED option was defined.
#define WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED \
((uint32_t)0x00000002)
// --------
// wuffs_base__empty_struct is used when a Wuffs function returns an empty
+10 -4
View File
@@ -1003,12 +1003,18 @@ func (g *gen) writeInitializerImpl(b *buffer, n *a.Struct) error {
b.writes("if (((wuffs_version >> 32) != WUFFS_VERSION_MAJOR) || " +
"(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {\n")
b.writes("return wuffs_base__error__bad_wuffs_version;\n")
b.writes("}\n")
b.writes("if ((initialize_flags & WUFFS_INITIALIZE__ALREADY_ZEROED) == 0) {\n")
b.writes("memset(&(self->private_impl), 0, sizeof(self->private_impl));\n")
b.writes("} else if (self->private_impl.magic != 0) {\n")
b.writes("}\n\n")
b.writes("if ((initialize_flags & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {\n")
b.writes("if (self->private_impl.magic != 0) {\n")
b.writes("return wuffs_base__error__initialize_falsely_claimed_already_zeroed;\n")
b.writes("}\n")
b.writes("} else if ((initialize_flags & WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) != 0) {\n")
b.writes("memset(&(self->private_impl), 0, sizeof(self->private_impl));\n")
b.writes("} else {\n")
b.writes("memset(self, 0, sizeof(*self));\n")
b.writes("initialize_flags |= WUFFS_INITIALIZE__ALREADY_ZEROED;\n")
b.writes("}\n\n")
// Call any ctors on sub-structs.
for _, f := range n.Fields() {
+2 -1
View File
@@ -63,7 +63,8 @@ const baseCorePrivateH = "" +
const baseCorePublicH = "" +
"// Wuffs assumes that:\n// - converting a uint32_t to a size_t will never overflow.\n// - converting a size_t to a uint64_t will never overflow.\n#ifdef __WORDSIZE\n#if (__WORDSIZE != 32) && (__WORDSIZE != 64)\n#error \"Wuffs requires a word size of either 32 or 64 bits\"\n#endif\n#endif\n\n// WUFFS_VERSION is the major.minor.patch version, as per https://semver.org/,\n// as a uint64_t. The major number is the high 32 bits. The minor number is the\n// middle 16 bits. The patch number is the low 16 bits. The pre-release label\n// and build metadata are part of the string representation (such as\n// \"1.2.3-beta+456.20181231\") but not the uint64_t representation.\n//\n// WUFFS_VERSION_PRE_RELEASE_LABEL (such as \"\", \"beta\" or \"rc.1\") being\n// non-empty denotes a developer preview, not a release version, and has no\n// backwards or forwards compatibility guarantees.\n//\n// WUFFS_VERSION_BUILD_METADATA_XXX, if non-zero, are the number of commits and\n// the last commit date in the repository used to build this library. Within\n// eac" +
"h major.minor branch, the commit count should increase monotonically.\n//\n// !! Some code generation programs can override WUFFS_VERSION.\n#define WUFFS_VERSION ((uint64_t)0)\n#define WUFFS_VERSION_MAJOR ((uint64_t)0)\n#define WUFFS_VERSION_MINOR ((uint64_t)0)\n#define WUFFS_VERSION_PATCH ((uint64_t)0)\n#define WUFFS_VERSION_PRE_RELEASE_LABEL \"work.in.progress\"\n#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 0\n#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 0\n#define WUFFS_VERSION_STRING \"0.0.0+0.00000000\"\n\n// Define WUFFS_CONFIG__STATIC_FUNCTIONS to make all of Wuffs' functions have\n// static storage. The motivation is discussed in the \"ALLOW STATIC\n// IMPLEMENTATION\" section of\n// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt\n#ifdef WUFFS_CONFIG__STATIC_FUNCTIONS\n#define WUFFS_BASE__MAYBE_STATIC static\n#else\n#define WUFFS_BASE__MAYBE_STATIC\n#endif\n\n// Clang also defines \"__GNUC__\".\n#if defined(__GNUC__)\n#define WUFFS_BASE__POTENTIALLY_UNUSED __attribute__((unused))\n#define WUFFS_BASE" +
"__WARN_UNUSED_RESULT __attribute__((warn_unused_result))\n#else\n#define WUFFS_BASE__POTENTIALLY_UNUSED\n#define WUFFS_BASE__WARN_UNUSED_RESULT\n#endif\n\n// Flags for wuffs_foo__bar__initialize functions.\n\n// WUFFS_INITIALIZE__ALREADY_ZEROED means that the \"self\" receiver struct value\n// has already been set to all zeroes.\n#define WUFFS_INITIALIZE__ALREADY_ZEROED ((uint32_t)0x00000001)\n\n" +
"__WARN_UNUSED_RESULT __attribute__((warn_unused_result))\n#else\n#define WUFFS_BASE__POTENTIALLY_UNUSED\n#define WUFFS_BASE__WARN_UNUSED_RESULT\n#endif\n\n// Flags for wuffs_foo__bar__initialize functions.\n\n// WUFFS_INITIALIZE__ALREADY_ZEROED means that the \"self\" receiver struct value\n// has already been set to all zeroes.\n#define WUFFS_INITIALIZE__ALREADY_ZEROED ((uint32_t)0x00000001)\n\n// WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED means that, absent\n// WUFFS_INITIALIZE__ALREADY_ZEROED, only some of the \"self\" receiver struct\n// value will be set to all zeroes. Internal buffers, which tend to be a large\n// proportion of the struct's size, will be left uninitialized. Internal means\n// that the buffer is contained by the receiver struct, as opposed to being\n// passed as a separately allocated \"work buffer\".\n//\n// With or without this bit set, the Wuffs compiler still enforces that no\n// reads or writes will overflow internal buffers' bounds. Even with this bit\n// set, the Wuffs standard library also cons" +
"iders reading from an uninitialized\n// buffer to be a bug, and strives to never do so, but unlike buffer overflows,\n// it is not a bug class that the Wuffs compiler eliminates.\n//\n// For those paranoid about security, leave this bit unset, so that\n// wuffs_foo__bar__initialize will initialize the entire struct value to zeroes\n// (unless WUFFS_INITIALIZE__ALREADY_ZEROED is set).\n//\n// Setting this bit gives a small absolute improvement on micro-benchmarks, but\n// this can be a large relative effect, up to 2x faster, when the actual work\n// to be done is also small, such as decompressing small input. See git commit\n// 438fc105 \"Move some struct fields to private_data\" for some numbers and a\n// discussion, noting that its commit message was written before this\n// WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED option was defined.\n#define WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED \\\n ((uint32_t)0x00000002)\n\n" +
"" +
"// --------\n\n// wuffs_base__empty_struct is used when a Wuffs function returns an empty\n// struct. In C, if a function f returns void, you can't say \"x = f()\", but in\n// Wuffs, if a function g returns empty, you can say \"y = g()\".\ntypedef struct {\n // private_impl is a placeholder field. It isn't explicitly used, except that\n // without it, the sizeof a struct with no fields can differ across C/C++\n // compilers, and it is undefined behavior in C99. For example, gcc says that\n // the sizeof an empty struct is 0, and g++ says that it is 1. This leads to\n // ABI incompatibility if a Wuffs .c file is processed by one compiler and\n // its .h file with another compiler.\n //\n // Instead, we explicitly insert an otherwise unused field, so that the\n // sizeof this struct is always 1.\n uint8_t private_impl;\n} wuffs_base__empty_struct;\n\n// wuffs_base__utility is a placeholder receiver type. It enables what Java\n// calls static methods, as opposed to regular methods.\ntypedef struct {\n // private_impl is a pla" +
"ceholder field. It isn't explicitly used, except that\n // without it, the sizeof a struct with no fields can differ across C/C++\n // compilers, and it is undefined behavior in C99. For example, gcc says that\n // the sizeof an empty struct is 0, and g++ says that it is 1. This leads to\n // ABI incompatibility if a Wuffs .c file is processed by one compiler and\n // its .h file with another compiler.\n //\n // Instead, we explicitly insert an otherwise unused field, so that the\n // sizeof this struct is always 1.\n uint8_t private_impl;\n} wuffs_base__utility;\n\n" +
+103 -21
View File
@@ -88,6 +88,32 @@ extern "C" {
// has already been set to all zeroes.
#define WUFFS_INITIALIZE__ALREADY_ZEROED ((uint32_t)0x00000001)
// WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED means that, absent
// WUFFS_INITIALIZE__ALREADY_ZEROED, only some of the "self" receiver struct
// value will be set to all zeroes. Internal buffers, which tend to be a large
// proportion of the struct's size, will be left uninitialized. Internal means
// that the buffer is contained by the receiver struct, as opposed to being
// passed as a separately allocated "work buffer".
//
// With or without this bit set, the Wuffs compiler still enforces that no
// reads or writes will overflow internal buffers' bounds. Even with this bit
// set, the Wuffs standard library also considers reading from an uninitialized
// buffer to be a bug, and strives to never do so, but unlike buffer overflows,
// it is not a bug class that the Wuffs compiler eliminates.
//
// For those paranoid about security, leave this bit unset, so that
// wuffs_foo__bar__initialize will initialize the entire struct value to zeroes
// (unless WUFFS_INITIALIZE__ALREADY_ZEROED is set).
//
// Setting this bit gives a small absolute improvement on micro-benchmarks, but
// this can be a large relative effect, up to 2x faster, when the actual work
// to be done is also small, such as decompressing small input. See git commit
// 438fc105 "Move some struct fields to private_data" for some numbers and a
// discussion, noting that its commit message was written before this
// WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED option was defined.
#define WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED \
((uint32_t)0x00000002)
// --------
// wuffs_base__empty_struct is used when a Wuffs function returns an empty
@@ -4965,11 +4991,19 @@ wuffs_adler32__hasher__initialize(wuffs_adler32__hasher* self,
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
return wuffs_base__error__bad_wuffs_version;
}
if ((initialize_flags & WUFFS_INITIALIZE__ALREADY_ZEROED) == 0) {
if ((initialize_flags & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
if (self->private_impl.magic != 0) {
return wuffs_base__error__initialize_falsely_claimed_already_zeroed;
}
} else if ((initialize_flags &
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) != 0) {
memset(&(self->private_impl), 0, sizeof(self->private_impl));
} else if (self->private_impl.magic != 0) {
return wuffs_base__error__initialize_falsely_claimed_already_zeroed;
} else {
memset(self, 0, sizeof(*self));
initialize_flags |= WUFFS_INITIALIZE__ALREADY_ZEROED;
}
self->private_impl.magic = WUFFS_BASE__MAGIC;
return NULL;
}
@@ -5964,11 +5998,19 @@ wuffs_crc32__ieee_hasher__initialize(wuffs_crc32__ieee_hasher* self,
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
return wuffs_base__error__bad_wuffs_version;
}
if ((initialize_flags & WUFFS_INITIALIZE__ALREADY_ZEROED) == 0) {
if ((initialize_flags & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
if (self->private_impl.magic != 0) {
return wuffs_base__error__initialize_falsely_claimed_already_zeroed;
}
} else if ((initialize_flags &
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) != 0) {
memset(&(self->private_impl), 0, sizeof(self->private_impl));
} else if (self->private_impl.magic != 0) {
return wuffs_base__error__initialize_falsely_claimed_already_zeroed;
} else {
memset(self, 0, sizeof(*self));
initialize_flags |= WUFFS_INITIALIZE__ALREADY_ZEROED;
}
self->private_impl.magic = WUFFS_BASE__MAGIC;
return NULL;
}
@@ -6242,11 +6284,19 @@ wuffs_deflate__decoder__initialize(wuffs_deflate__decoder* self,
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
return wuffs_base__error__bad_wuffs_version;
}
if ((initialize_flags & WUFFS_INITIALIZE__ALREADY_ZEROED) == 0) {
if ((initialize_flags & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
if (self->private_impl.magic != 0) {
return wuffs_base__error__initialize_falsely_claimed_already_zeroed;
}
} else if ((initialize_flags &
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) != 0) {
memset(&(self->private_impl), 0, sizeof(self->private_impl));
} else if (self->private_impl.magic != 0) {
return wuffs_base__error__initialize_falsely_claimed_already_zeroed;
} else {
memset(self, 0, sizeof(*self));
initialize_flags |= WUFFS_INITIALIZE__ALREADY_ZEROED;
}
self->private_impl.magic = WUFFS_BASE__MAGIC;
return NULL;
}
@@ -8025,11 +8075,19 @@ wuffs_lzw__decoder__initialize(wuffs_lzw__decoder* self,
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
return wuffs_base__error__bad_wuffs_version;
}
if ((initialize_flags & WUFFS_INITIALIZE__ALREADY_ZEROED) == 0) {
if ((initialize_flags & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
if (self->private_impl.magic != 0) {
return wuffs_base__error__initialize_falsely_claimed_already_zeroed;
}
} else if ((initialize_flags &
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) != 0) {
memset(&(self->private_impl), 0, sizeof(self->private_impl));
} else if (self->private_impl.magic != 0) {
return wuffs_base__error__initialize_falsely_claimed_already_zeroed;
} else {
memset(self, 0, sizeof(*self));
initialize_flags |= WUFFS_INITIALIZE__ALREADY_ZEROED;
}
self->private_impl.magic = WUFFS_BASE__MAGIC;
return NULL;
}
@@ -8601,11 +8659,19 @@ wuffs_gif__decoder__initialize(wuffs_gif__decoder* self,
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
return wuffs_base__error__bad_wuffs_version;
}
if ((initialize_flags & WUFFS_INITIALIZE__ALREADY_ZEROED) == 0) {
if ((initialize_flags & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
if (self->private_impl.magic != 0) {
return wuffs_base__error__initialize_falsely_claimed_already_zeroed;
}
} else if ((initialize_flags &
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) != 0) {
memset(&(self->private_impl), 0, sizeof(self->private_impl));
} else if (self->private_impl.magic != 0) {
return wuffs_base__error__initialize_falsely_claimed_already_zeroed;
} else {
memset(self, 0, sizeof(*self));
initialize_flags |= WUFFS_INITIALIZE__ALREADY_ZEROED;
}
{
wuffs_base__status z = wuffs_lzw__decoder__initialize(
&self->private_data.f_lzw, sizeof(self->private_data.f_lzw),
@@ -10756,11 +10822,19 @@ wuffs_gzip__decoder__initialize(wuffs_gzip__decoder* self,
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
return wuffs_base__error__bad_wuffs_version;
}
if ((initialize_flags & WUFFS_INITIALIZE__ALREADY_ZEROED) == 0) {
if ((initialize_flags & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
if (self->private_impl.magic != 0) {
return wuffs_base__error__initialize_falsely_claimed_already_zeroed;
}
} else if ((initialize_flags &
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) != 0) {
memset(&(self->private_impl), 0, sizeof(self->private_impl));
} else if (self->private_impl.magic != 0) {
return wuffs_base__error__initialize_falsely_claimed_already_zeroed;
} else {
memset(self, 0, sizeof(*self));
initialize_flags |= WUFFS_INITIALIZE__ALREADY_ZEROED;
}
{
wuffs_base__status z = wuffs_crc32__ieee_hasher__initialize(
&self->private_data.f_checksum, sizeof(self->private_data.f_checksum),
@@ -11229,11 +11303,19 @@ wuffs_zlib__decoder__initialize(wuffs_zlib__decoder* self,
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
return wuffs_base__error__bad_wuffs_version;
}
if ((initialize_flags & WUFFS_INITIALIZE__ALREADY_ZEROED) == 0) {
if ((initialize_flags & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
if (self->private_impl.magic != 0) {
return wuffs_base__error__initialize_falsely_claimed_already_zeroed;
}
} else if ((initialize_flags &
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) != 0) {
memset(&(self->private_impl), 0, sizeof(self->private_impl));
} else if (self->private_impl.magic != 0) {
return wuffs_base__error__initialize_falsely_claimed_already_zeroed;
} else {
memset(self, 0, sizeof(*self));
initialize_flags |= WUFFS_INITIALIZE__ALREADY_ZEROED;
}
{
wuffs_base__status z = wuffs_adler32__hasher__initialize(
&self->private_data.f_checksum, sizeof(self->private_data.f_checksum),
+7 -4
View File
@@ -130,8 +130,9 @@ const char* test_wuffs_adler32_golden() {
int j;
for (j = 0; j < 2; j++) {
wuffs_adler32__hasher checksum;
status = wuffs_adler32__hasher__initialize(&checksum, sizeof checksum,
WUFFS_VERSION, 0);
status = wuffs_adler32__hasher__initialize(
&checksum, sizeof checksum, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
RETURN_FAIL("initialize: \"%s\"", status);
}
@@ -193,7 +194,8 @@ const char* test_wuffs_adler32_pi() {
for (i = 0; i < 64; i++) {
wuffs_adler32__hasher checksum;
const char* status = wuffs_adler32__hasher__initialize(
&checksum, sizeof checksum, WUFFS_VERSION, 0);
&checksum, sizeof checksum, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
RETURN_FAIL("initialize: \"%s\"", status);
}
@@ -224,7 +226,8 @@ const char* wuffs_bench_adler32(wuffs_base__io_buffer* dst,
}
wuffs_adler32__hasher checksum;
const char* status = wuffs_adler32__hasher__initialize(
&checksum, sizeof checksum, WUFFS_VERSION, 0);
&checksum, sizeof checksum, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
return status;
}
+7 -4
View File
@@ -130,8 +130,9 @@ const char* test_wuffs_crc32_ieee_golden() {
int j;
for (j = 0; j < 2; j++) {
wuffs_crc32__ieee_hasher checksum;
status = wuffs_crc32__ieee_hasher__initialize(&checksum, sizeof checksum,
WUFFS_VERSION, 0);
status = wuffs_crc32__ieee_hasher__initialize(
&checksum, sizeof checksum, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
RETURN_FAIL("initialize: \"%s\"", status);
}
@@ -214,7 +215,8 @@ const char* do_test_xxxxx_crc32_ieee_pi(bool mimic) {
} else {
wuffs_crc32__ieee_hasher checksum;
const char* status = wuffs_crc32__ieee_hasher__initialize(
&checksum, sizeof checksum, WUFFS_VERSION, 0);
&checksum, sizeof checksum, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
RETURN_FAIL("initialize: \"%s\"", status);
}
@@ -259,7 +261,8 @@ const char* wuffs_bench_crc32_ieee(wuffs_base__io_buffer* dst,
}
wuffs_crc32__ieee_hasher checksum;
const char* status = wuffs_crc32__ieee_hasher__initialize(
&checksum, sizeof checksum, WUFFS_VERSION, 0);
&checksum, sizeof checksum, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
return status;
}
+15 -10
View File
@@ -140,8 +140,9 @@ const char* wuffs_deflate_decode(wuffs_base__io_buffer* dst,
uint64_t wlimit,
uint64_t rlimit) {
wuffs_deflate__decoder dec;
const char* status =
wuffs_deflate__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0);
const char* status = wuffs_deflate__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
RETURN_FAIL("initialize: \"%s\"", status);
}
@@ -267,8 +268,9 @@ const char* test_wuffs_deflate_decode_split_src() {
got.meta.wi = 0;
wuffs_deflate__decoder dec;
status =
wuffs_deflate__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0);
status = wuffs_deflate__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
RETURN_FAIL("initialize: \"%s\"", status);
}
@@ -362,8 +364,9 @@ const char* test_wuffs_deflate_history_full() {
int i;
for (i = -2; i <= +2; i++) {
wuffs_deflate__decoder dec;
status =
wuffs_deflate__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0);
status = wuffs_deflate__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
RETURN_FAIL("initialize: \"%s\"", status);
}
@@ -442,8 +445,9 @@ const char* test_wuffs_deflate_history_partial() {
wuffs_deflate__decoder dec;
memset(&(dec.private_data.f_history), 0,
sizeof(dec.private_data.f_history));
status =
wuffs_deflate__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0);
status = wuffs_deflate__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
RETURN_FAIL("initialize: \"%s\"", status);
}
@@ -529,8 +533,9 @@ const char* test_wuffs_deflate_table_redirect() {
// 2nd is the key in the second level table (variable bits).
wuffs_deflate__decoder dec;
const char* status =
wuffs_deflate__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0);
const char* status = wuffs_deflate__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
RETURN_FAIL("initialize: \"%s\"", status);
}
+44 -18
View File
@@ -85,8 +85,9 @@ const char* test_basic_bad_receiver() {
const char* test_basic_bad_sizeof_receiver() {
CHECK_FOCUS(__func__);
wuffs_gif__decoder dec;
const char* status =
wuffs_gif__decoder__initialize(&dec, 0, WUFFS_VERSION, 0);
const char* status = wuffs_gif__decoder__initialize(
&dec, 0, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status != wuffs_base__error__bad_sizeof_receiver) {
RETURN_FAIL("decode_image_config: got \"%s\", want \"%s\"", status,
wuffs_base__error__bad_sizeof_receiver);
@@ -98,7 +99,8 @@ const char* test_basic_bad_wuffs_version() {
CHECK_FOCUS(__func__);
wuffs_gif__decoder dec;
const char* status = wuffs_gif__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION ^ 0x123456789ABC, 0);
&dec, sizeof dec, WUFFS_VERSION ^ 0x123456789ABC,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status != wuffs_base__error__bad_wuffs_version) {
RETURN_FAIL("decode_image_config: got \"%s\", want \"%s\"", status,
wuffs_base__error__bad_wuffs_version);
@@ -171,8 +173,9 @@ const char* test_basic_status_used_package() {
const char* test_basic_sub_struct_initializer() {
CHECK_FOCUS(__func__);
wuffs_gif__decoder dec;
const char* status =
wuffs_gif__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0);
const char* status = wuffs_gif__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
RETURN_FAIL("initialize: \"%s\"", status);
}
@@ -193,8 +196,9 @@ const char* wuffs_gif_decode(wuffs_base__io_buffer* dst,
wuffs_base__pixel_format pixfmt,
wuffs_base__io_buffer* src) {
wuffs_gif__decoder dec;
const char* status =
wuffs_gif__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0);
const char* status = wuffs_gif__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
return status;
}
@@ -260,7 +264,9 @@ const char* do_test_wuffs_gif_decode(const char* filename,
}
wuffs_gif__decoder dec;
status = wuffs_gif__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0);
status = wuffs_gif__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
RETURN_FAIL("initialize: \"%s\"", status);
}
@@ -474,7 +480,9 @@ const char* test_wuffs_gif_call_interleaved() {
}
wuffs_gif__decoder dec;
status = wuffs_gif__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0);
status = wuffs_gif__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
RETURN_FAIL("initialize: \"%s\"", status);
}
@@ -520,7 +528,9 @@ const char* test_wuffs_gif_call_sequence() {
}
wuffs_gif__decoder dec;
status = wuffs_gif__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0);
status = wuffs_gif__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
RETURN_FAIL("initialize: \"%s\"", status);
}
@@ -555,7 +565,9 @@ const char* do_test_wuffs_gif_decode_animated(
}
wuffs_gif__decoder dec;
status = wuffs_gif__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0);
status = wuffs_gif__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
RETURN_FAIL("initialize: \"%s\"", status);
}
@@ -678,7 +690,9 @@ const char* test_wuffs_gif_decode_frame_out_of_bounds() {
}
wuffs_gif__decoder dec;
status = wuffs_gif__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0);
status = wuffs_gif__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
RETURN_FAIL("initialize: \"%s\"", status);
}
@@ -857,7 +871,9 @@ const char* test_wuffs_gif_decode_input_is_a_png() {
}
wuffs_gif__decoder dec;
status = wuffs_gif__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0);
status = wuffs_gif__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
RETURN_FAIL("initialize: \"%s\"", status);
}
@@ -891,7 +907,9 @@ const char* test_wuffs_gif_decode_missing_two_src_bytes() {
src.meta.wi -= 2;
wuffs_gif__decoder dec;
status = wuffs_gif__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0);
status = wuffs_gif__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
RETURN_FAIL("initialize: \"%s\"", status);
}
@@ -938,7 +956,9 @@ const char* test_wuffs_gif_decode_multiple_loop_counts() {
}
wuffs_gif__decoder dec;
status = wuffs_gif__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0);
status = wuffs_gif__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
RETURN_FAIL("initialize: \"%s\"", status);
}
@@ -1004,7 +1024,9 @@ const char* test_wuffs_gif_frame_dirty_rect() {
}
wuffs_gif__decoder dec;
status = wuffs_gif__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0);
status = wuffs_gif__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
RETURN_FAIL("initialize: \"%s\"", status);
}
@@ -1067,7 +1089,9 @@ const char* do_test_wuffs_gif_num_decoded(bool frame_config) {
}
wuffs_gif__decoder dec;
status = wuffs_gif__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0);
status = wuffs_gif__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
RETURN_FAIL("initialize: \"%s\"", status);
}
@@ -1147,7 +1171,9 @@ const char* do_test_wuffs_gif_io_position(bool chunked) {
}
wuffs_gif__decoder dec;
status = wuffs_gif__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0);
status = wuffs_gif__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
RETURN_FAIL("initialize: \"%s\"", status);
}
+6 -4
View File
@@ -88,8 +88,9 @@ const char* wuffs_gzip_decode(wuffs_base__io_buffer* dst,
uint64_t wlimit,
uint64_t rlimit) {
wuffs_gzip__decoder dec;
const char* status =
wuffs_gzip__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0);
const char* status = wuffs_gzip__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
return status;
}
@@ -140,8 +141,9 @@ const char* do_test_wuffs_gzip_checksum(bool ignore_checksum,
int end_limit;
for (end_limit = 0; end_limit < 10; end_limit++) {
wuffs_gzip__decoder dec;
status =
wuffs_gzip__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0);
status = wuffs_gzip__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
RETURN_FAIL("initialize: \"%s\"", status);
}
+12 -6
View File
@@ -108,7 +108,9 @@ const char* do_test_wuffs_lzw_decode(const char* src_filename,
}
wuffs_lzw__decoder dec;
status = wuffs_lzw__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0);
status = wuffs_lzw__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
RETURN_FAIL("initialize: \"%s\"", status);
}
@@ -224,8 +226,9 @@ const char* test_wuffs_lzw_decode_output_bad() {
src.data.ptr[3] = 0xFF;
wuffs_lzw__decoder dec;
const char* status =
wuffs_lzw__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0);
const char* status = wuffs_lzw__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
RETURN_FAIL("initialize: \"%s\"", status);
}
@@ -268,8 +271,9 @@ const char* test_wuffs_lzw_decode_output_empty() {
src.data.ptr[1] = 0x01;
wuffs_lzw__decoder dec;
const char* status =
wuffs_lzw__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0);
const char* status = wuffs_lzw__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
RETURN_FAIL("initialize: \"%s\"", status);
}
@@ -325,7 +329,9 @@ const char* do_bench_wuffs_lzw_decode(const char* filename,
got.meta.wi = 0;
src.meta.ri = 1; // Skip the literal width.
wuffs_lzw__decoder dec;
status = wuffs_lzw__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0);
status = wuffs_lzw__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
RETURN_FAIL("initialize: \"%s\"", status);
}
+6 -4
View File
@@ -88,8 +88,9 @@ const char* wuffs_zlib_decode(wuffs_base__io_buffer* dst,
uint64_t wlimit,
uint64_t rlimit) {
wuffs_zlib__decoder dec;
const char* status =
wuffs_zlib__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0);
const char* status = wuffs_zlib__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
return status;
}
@@ -139,8 +140,9 @@ const char* do_test_wuffs_zlib_checksum(bool ignore_checksum,
int end_limit;
for (end_limit = 0; end_limit < 10; end_limit++) {
wuffs_zlib__decoder dec;
status =
wuffs_zlib__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0);
status = wuffs_zlib__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
RETURN_FAIL("initialize: \"%s\"", status);
}