commit 2aeddf9c1b0f33b94a01a0c307e3408b89e746c5 from: Omar Polo date: Sun Jul 18 17:34:15 2021 UTC emit a dummy NUL byte on empty files an empty initializer, such as uint8_t foo[] = { }; raises a warning: "use of GNU empty initializer extension" using -pedantic. This adds a dummy NUL byte that's not accounted in the len counter. So, now it produces: uint8_t foo[] = { 0x0 }; size_t foo_len = 0; commit - 0ce8aa3ef6cc677ab907e74becbe9fce44fbe3eb commit + 2aeddf9c1b0f33b94a01a0c307e3408b89e746c5 blob - 0ae6f24d8ac4d26741ef8894b8152b46a69f5620 blob + 57991d3be50c6e5da66de728fe6b4435bf31bbb7 --- pagebundler.c +++ pagebundler.c @@ -35,7 +35,7 @@ int main(int argc, char **argv) { size_t len, r, i; - int ch; + int ch, did; FILE *f; uint8_t buf[64]; @@ -67,11 +67,15 @@ main(int argc, char **argv) printf("const uint8_t %s[] = {\n", varname); + did = 0; len = 0; for (;;) { r = fread(buf, 1, sizeof(buf), f); len += r; + if (r != 0) + did = 1; + printf("\t"); for (i = 0; i < r; ++i) { printf("0x%x, ", buf[i]); @@ -82,6 +86,17 @@ main(int argc, char **argv) break; } + if (!did) { + /* + * if nothing was emitted, add a NUL byte. This was + * still produce an exact copy of the file because + * `len' doesn't count this NUL byte. It prevents the + * "use of GNU empty initializer extension" warning + * when bundling pages/about_empty.gmi + */ + printf("\t0x0\n"); + } + printf("}; /* %s */\n", varname); printf("size_t %s_len = %zu;\n", varname, len);