This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] compile-loc2c: Fix uninitialized variable error


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=266934d1ad029100f4073f9e351f8685ea175b83

commit 266934d1ad029100f4073f9e351f8685ea175b83
Author: Simon Marchi <simon.marchi@ericsson.com>
Date:   Sun Jul 9 20:25:38 2017 +0200

    compile-loc2c: Fix uninitialized variable error
    
    Compiling with clang gives this warning/error:
    
      /home/emaisin/src/binutils-gdb/gdb/compile/compile-loc2c.c:731:6: error: variable 'uoffset' is uninitialized when used here [-Werror,-Wuninitialized]
                  uoffset += dwarf2_per_cu_text_offset (per_cu);
                  ^~~~~~~
      /home/emaisin/src/binutils-gdb/gdb/compile/compile-loc2c.c:669:23: note: initialize the variable 'uoffset' to silence this warning
            uint64_t uoffset, reg;
                            ^
                             = 0
    
    I am really not sure if what this patch does is good, but it is my best
    guess.  DW_OP_addr means that there's an constant address provided by
    the DWARF bytecode that should be pushed on the stack.  That address is
    considered skipped by the "op_ptr += addr_size", but it is never read.
    uoffset is indeed read just after, without having been assigned first.
    
    So I think the intent is to read the address, it was just omitted.
    
    gdb/ChangeLog:
    
    	* compile/compile-loc2c.c (do_compile_dwarf_expr_to_c): Read
    	address when op is DW_OP_addr.

Diff:
---
 gdb/ChangeLog               | 5 +++++
 gdb/compile/compile-loc2c.c | 1 +
 2 files changed, 6 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 86a41b6..8ccd7a4 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2017-07-09  Simon Marchi  <simon.marchi@ericsson.com>
+
+	* compile/compile-loc2c.c (do_compile_dwarf_expr_to_c): Read
+	address when op is DW_OP_addr.
+
 2017-07-09  Tom Tromey  <tom@tromey.com>
 
 	* dwarf2loc.c (dwarf2_evaluate_loc_desc_full): Reverse size
diff --git a/gdb/compile/compile-loc2c.c b/gdb/compile/compile-loc2c.c
index a53214f..ead1003 100644
--- a/gdb/compile/compile-loc2c.c
+++ b/gdb/compile/compile-loc2c.c
@@ -722,6 +722,7 @@ do_compile_dwarf_expr_to_c (int indent, string_file &stream,
 	  break;
 
 	case DW_OP_addr:
+	  uoffset = extract_unsigned_integer (op_ptr, addr_size, byte_order);
 	  op_ptr += addr_size;
 	  /* Some versions of GCC emit DW_OP_addr before
 	     DW_OP_GNU_push_tls_address.  In this case the value is an


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]