From daa0924312ce93fafc9479263bde458f47c9787d Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Sun, 22 Jan 2023 14:52:27 +0000 Subject: [PATCH] Tools: Check error codes --- src/grib_index.c | 6 +++--- tools/grib_index_build.c | 4 +++- tools/grib_tools.c | 18 ++++++++++-------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/grib_index.c b/src/grib_index.c index a31435424..4aeab0043 100644 --- a/src/grib_index.c +++ b/src/grib_index.c @@ -218,10 +218,10 @@ int grib_index_compress(grib_index* index) return 0; err = grib_index_keys_compress(c, index, compress); - if (err) - return err; + if (err) return err; - grib_index_fields_compress(c, index->fields, 0, 0, compress); + err = grib_index_fields_compress(c, index->fields, 0, 0, compress); + if (err) return err; if (!index->fields->next) { grib_field_tree* next_level = index->fields->next_level; diff --git a/tools/grib_index_build.c b/tools/grib_index_build.c index 6a13586c1..5d1d16915 100644 --- a/tools/grib_index_build.c +++ b/tools/grib_index_build.c @@ -112,9 +112,11 @@ int grib_tool_finalise_action(grib_runtime_options* options) grib_index_key* the_keys; grib_string_list* values; int first; + int err = 0; if (compress_index) { - grib_index_compress(idx); + err = grib_index_compress(idx); + if (err) return err; } printf("--- %s: keys included in the index file %s:\n", tool_name, options->outfile->name); diff --git a/tools/grib_tools.c b/tools/grib_tools.c index 71376638f..baaf2267d 100644 --- a/tools/grib_tools.c +++ b/tools/grib_tools.c @@ -594,7 +594,7 @@ static int scan(grib_context* c, grib_runtime_options* options, const char* dir) } } closedir(d); - return 0; + return err; } #else static int scan(grib_context* c, grib_runtime_options* options, const char* dir) @@ -627,6 +627,7 @@ static int process(grib_context* c, grib_runtime_options* options, const char* p { struct stat s; int stat_val = 0; + int err = 0; #ifndef ECCODES_ON_WINDOWS stat_val = lstat(path, &s); @@ -640,28 +641,29 @@ static int process(grib_context* c, grib_runtime_options* options, const char* p } if (S_ISDIR(s.st_mode) && !S_ISLNK(s.st_mode)) { - scan(c, options, path); + err = scan(c, options, path); } else { - grib_tool_new_filename_action(options, path); + err = grib_tool_new_filename_action(options, path); } - return 0; + return err; } static int grib_tool_onlyfiles(grib_runtime_options* options) { grib_context* c = grib_context_get_default(); grib_tools_file* infile = options->infile; + int err = 0; while (infile != NULL && infile->name != NULL) { - process(c, options, infile->name); - + err = process(c, options, infile->name); + if (err) return err; infile = infile->next; } - grib_tool_finalise_action(options); + err = grib_tool_finalise_action(options); - return 0; + return err; } static void grib_print_header(grib_runtime_options* options, grib_handle* h)