From 83a16763c88d833fa299e8c768361b1041d87bb5 Mon Sep 17 00:00:00 2001 From: Joris Vink Date: Mon, 18 Aug 2014 13:57:06 +0200 Subject: [PATCH] Always NUL-terminate an asset its data. This way developers can cast assets to char * without first having to convert it to a proper C string. The NUL character is NOT included in the length of the asset. --- src/cli.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cli.c b/src/cli.c index 7c39d03..470cc49 100644 --- a/src/cli.c +++ b/src/cli.c @@ -618,6 +618,13 @@ cli_build_asset(char *fpath, struct dirent *dp) for (off = 0; off < st.st_size; off++) cli_file_writef(out, "0x%02x,", *d++); + /* + * Always NUL-terminate the asset, even if this NUL is not included in + * the actual length. This way assets can be cast to char * without + * any additional thinking for the developer. + */ + cli_file_writef(out, "0x00"); + /* Add the meta data. */ cli_file_writef(out, "};\n\n"); cli_file_writef(out, "u_int32_t asset_len_%s_%s = %" PRIu32 ";\n",