stardis-green

Post-processing of green functions
git clone git://git.meso-star.fr/stardis-green.git
Log | Files | Refs | README | LICENSE

commit 0e314a80d39abf0f970c5c9ac90434a261f81156
parent 7a0fb492a8b3f57b82d12675afac09381b1dc0c7
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Fri, 20 Nov 2020 09:32:48 +0100

Check file format version for binary green files

Diffstat:
Msrc/green-input.c | 21++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/src/green-input.c b/src/green-input.c @@ -61,18 +61,29 @@ read_green_function res_T res = RES_OK; unsigned i; char* pool_ptr; - char expected[] = "BINGREEN"; - char tmp[sizeof(expected)]; + const char expected_green_string[] = "GREEN_BIN_FILE:"; + const unsigned expected_file_fmt_version = 1; + char green_string[sizeof(expected_green_string)]; + unsigned file_fmt_version; ASSERT(green && stream); - /* Check Green string */ - FR(tmp, sizeof(tmp)); - if(strncmp(expected, tmp, sizeof(expected))) { + /* Check Green string and file format version */ + FR(green_string, sizeof(green_string)); + if(strncmp(expected_green_string, green_string, sizeof(expected_green_string))) + { logger_print(green->logger, LOG_ERROR, "File is not a binary Green file.\n"); res = RES_BAD_ARG; goto error; } + FR(&file_fmt_version, 1); + if(expected_file_fmt_version != file_fmt_version) { + logger_print(green->logger, LOG_ERROR, + "Incompatible file format version (%u VS expected %u).\n", + file_fmt_version, expected_file_fmt_version); + res = RES_BAD_ARG; + goto error; + } /* Read counts */ FR(&green->counts, 1);