[03/23] gallium/aux/util/u_debug_stack.c: Silence -Wunused-result warning

Submitted by Gert Wollny on Nov. 12, 2017, 1:55 p.m.

Details

Message ID 20171112135555.1385-4-gw.fossdev@gmail.com
State New
Headers show
Series "Silence some warnings that show up when compiling gallium/aux/util" ( rev: 1 ) in Mesa

Not browsing as part of any series.

Commit Message

Gert Wollny Nov. 12, 2017, 1:55 p.m.
asprintf is decorated with the attrbute "warn_unused_result", and if the
function call fails, the pointer "temp" will be undefined, but since it is
used later it should contain some usable value.
Test return value of asprintf and assign some save value to "temp" if
the call failed.
---
 src/gallium/auxiliary/util/u_debug_stack.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/gallium/auxiliary/util/u_debug_stack.c b/src/gallium/auxiliary/util/u_debug_stack.c
index 7013807b6b..f12ef73e91 100644
--- a/src/gallium/auxiliary/util/u_debug_stack.c
+++ b/src/gallium/auxiliary/util/u_debug_stack.c
@@ -90,9 +90,9 @@  symbol_name_cached(unw_cursor_t *cursor, unw_proc_info_t *pip)
          procname[1] = 0;
       }
 
-      asprintf(&name, "%s%s", procname, ret == -UNW_ENOMEM ? "..." : "");
-
-      util_hash_table_set(symbols_hash, addr, (void*)name);
+      if (asprintf(&name, "%s%s", procname, ret == -UNW_ENOMEM ? "..." : "") == -1) 
+		  name = "??";
+	   util_hash_table_set(symbols_hash, addr, (void*)name);
    }
    mtx_unlock(&symbols_mutex);
 

Comments

On 11/12/2017 06:55 AM, Gert Wollny wrote:
> asprintf is decorated with the attrbute "warn_unused_result", and if the
> function call fails, the pointer "temp" will be undefined, but since it is
> used later it should contain some usable value.
> Test return value of asprintf and assign some save value to "temp" if
> the call failed.
> ---
>   src/gallium/auxiliary/util/u_debug_stack.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/src/gallium/auxiliary/util/u_debug_stack.c b/src/gallium/auxiliary/util/u_debug_stack.c
> index 7013807b6b..f12ef73e91 100644
> --- a/src/gallium/auxiliary/util/u_debug_stack.c
> +++ b/src/gallium/auxiliary/util/u_debug_stack.c
> @@ -90,9 +90,9 @@ symbol_name_cached(unw_cursor_t *cursor, unw_proc_info_t *pip)
>            procname[1] = 0;
>         }
>
> -      asprintf(&name, "%s%s", procname, ret == -UNW_ENOMEM ? "..." : "");
> -
> -      util_hash_table_set(symbols_hash, addr, (void*)name);
> +      if (asprintf(&name, "%s%s", procname, ret == -UNW_ENOMEM ? "..." : "") == -1)
> +		  name = "??";
> +	   util_hash_table_set(symbols_hash, addr, (void*)name);

Indentation is wrong.  Please use spaces.

Same thing in patch 7.

>      }
>      mtx_unlock(&symbols_mutex);
>
>

The series look OK otherwise.

Reviewed-by: Brian Paul <brianp@vmware.com>