[PATCH] lib: fwts_log_*: fix a few smatch errors

Keng-Yu Lin kengyu at canonical.com
Fri Mar 8 08:36:50 UTC 2013


On Thu, Mar 7, 2013 at 2:49 AM, Colin King <colin.king at canonical.com> wrote:
> From: Colin Ian King <colin.king at canonical.com>
>
> Minor re-working to fix up some smatch errors in fwts_log_*.c,
> for example:
>
> fwts_log_xml.c:142 fwts_log_section_begin_xml() error:
>   testing array offset 'xml_stack_index' after use.
>
> Signed-off-by: Colin Ian King <colin.king at canonical.com>
> ---
>  src/lib/src/fwts_log_html.c | 7 +++----
>  src/lib/src/fwts_log_json.c | 8 ++++----
>  src/lib/src/fwts_log_xml.c  | 7 +++----
>  3 files changed, 10 insertions(+), 12 deletions(-)
>
> diff --git a/src/lib/src/fwts_log_html.c b/src/lib/src/fwts_log_html.c
> index 4b907c5..89557d4 100644
> --- a/src/lib/src/fwts_log_html.c
> +++ b/src/lib/src/fwts_log_html.c
> @@ -376,8 +376,6 @@ static void fwts_log_newline_html(fwts_log_file *log_file)
>
>  static void fwts_log_section_begin_html(fwts_log_file *log_file, const char *name)
>  {
> -       html_stack[html_stack_index].name = name;
> -
>         if (!strcmp(name, "summary")) {
>                 fwts_log_html(log_file, "<TR><TD class=style_heading COLSPAN=2>Summary</TD></TR>\n");
>         } else if (!strcmp(name, "heading")) {
> @@ -390,9 +388,10 @@ static void fwts_log_section_begin_html(fwts_log_file *log_file, const char *nam
>
>         fflush(log_file->fp);
>
> -       if (html_stack_index < MAX_HTML_STACK)
> +       if (html_stack_index < MAX_HTML_STACK) {
> +               html_stack[html_stack_index].name = name;
>                 html_stack_index++;
> -       else  {
> +       } else  {
>                 fprintf(stderr, "html log stack overflow pushing section %s.\n", name);
>                 exit(EXIT_FAILURE);
>         }
> diff --git a/src/lib/src/fwts_log_json.c b/src/lib/src/fwts_log_json.c
> index f83abc5..bf28c0c 100644
> --- a/src/lib/src/fwts_log_json.c
> +++ b/src/lib/src/fwts_log_json.c
> @@ -178,16 +178,16 @@ static void fwts_log_section_begin_json(fwts_log_file *log_file, const char *nam
>          */
>         json_object_object_add(json_obj, name, json_log);
>
> -       json_stack[json_stack_index].obj = json_obj;
> -       json_stack[json_stack_index].log = json_log;
>
>         if (json_stack_index > 0)
>                 if (json_object_array_add(json_stack[json_stack_index-1].log, json_obj) != 0)
>                         fwts_log_out_of_memory_json();
>
> -       if (json_stack_index < MAX_JSON_STACK)
> +       if (json_stack_index < MAX_JSON_STACK) {
> +               json_stack[json_stack_index].obj = json_obj;
> +               json_stack[json_stack_index].log = json_log;
>                 json_stack_index++;
> -       else  {
> +       } else  {
>                 fprintf(stderr, "json log stack overflow pushing section %s.\n", name);
>                 exit(EXIT_FAILURE);
>         }
> diff --git a/src/lib/src/fwts_log_xml.c b/src/lib/src/fwts_log_xml.c
> index b737357..393dfbe 100644
> --- a/src/lib/src/fwts_log_xml.c
> +++ b/src/lib/src/fwts_log_xml.c
> @@ -134,14 +134,13 @@ static void fwts_log_newline_xml(fwts_log_file *log_file)
>
>  static void fwts_log_section_begin_xml(fwts_log_file *log_file, const char *name)
>  {
> -       xml_stack[xml_stack_index].name = name;
> -
>         fprintf(log_file->fp, "%*s<%s>\n", xml_stack_index * XML_INDENT, "", name);
>         fflush(log_file->fp);
>
> -       if (xml_stack_index < MAX_XML_STACK)
> +       if (xml_stack_index < MAX_XML_STACK) {
> +               xml_stack[xml_stack_index].name = name;
>                 xml_stack_index++;
> -       else  {
> +       } else  {
>                 fprintf(stderr, "xml log stack overflow pushing section %s.\n", name);
>                 exit(EXIT_FAILURE);
>         }
> --
> 1.8.1.2
>
Acked-by: Keng-Yu Lin <kengyu at canonical.com>



More information about the fwts-devel mailing list