From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24378 invoked by alias); 20 Oct 2007 17:21:47 -0000 Received: (qmail 24327 invoked by uid 22791); 20 Oct 2007 17:21:46 -0000 X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (65.74.133.4) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sat, 20 Oct 2007 17:21:43 +0000 Received: (qmail 3934 invoked from network); 20 Oct 2007 17:21:41 -0000 Received: from unknown (HELO localhost) (carlos@127.0.0.2) by mail.codesourcery.com with ESMTPA; 20 Oct 2007 17:21:41 -0000 Date: Sat, 20 Oct 2007 18:07:00 -0000 From: Carlos O'Donell To: gdb-patches@sourceware.org Cc: Daniel Jacobowitz Subject: [PATCH] Fix uninitialized use of variables. Message-ID: <20071020172137.GC28823@lios> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.16 (2007-06-11) Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2007-10/txt/msg00468.txt.bz2 Compiling gdb head with gcc head reveals two uninitialized uses of variables. Analysis of the uninitialized uses reveals that gcc is correct. The following patch fixes both uninitiailized uses of variables. In remote.c (unpack_nibble) the variable *val is not set if ishex fails to find hex digits. Callers of unpack_nibble expect *val to be set. The solution is to check the return of ishex, and call error appropriately. In the case that *val is not set, the uninitialized use is never reached because we call error. In symtab.c (find_line_common) the variable *exact_match is not set if no match is found. Callers of find_line_common expect *exact_match to be set. The solution is to initialize *exact_match to zero, assuming an inexact match. In the case that we don't find a match in find_line_common, the statement `(best_index < 0 || !exact)' in symtab.c:2267 is true, instead of undefined. The comment is adjusted to indicate that one must look at another symtab if we failed to find a match `best_index < 0' or we found an inexact match `!exact.' No regressions on i686-pc-linux-gnu. OK to checkin? Cheers, Carlos. -- Carlos O'Donell CodeSourcery carlos@codesourcery.com (650) 331-3385 x716 gdb/ 2007-10-18 Carlos O'Donell * remote.c (unpack_nibble): error if buffer is not valid hex. * symtab.c (find_line_symtab): `no match' case is important. (find_line_common): Default *exact_match = 0 before search. Index: gdb/remote.c =================================================================== RCS file: /cvs/src/src/gdb/remote.c,v retrieving revision 1.271 diff -u -p -r1.271 remote.c --- gdb/remote.c 8 Oct 2007 12:55:09 -0000 1.271 +++ gdb/remote.c 18 Oct 2007 16:34:05 -0000 @@ -1343,7 +1343,8 @@ unpack_varlen_hex (char *buff, /* packet static char * unpack_nibble (char *buf, int *val) { - ishex (*buf++, val); + if (!ishex (*buf++, val)) + error (_("Unpacked nibble does not contain hex characters.")); return buf; } Index: gdb/symtab.c =================================================================== RCS file: /cvs/src/src/gdb/symtab.c,v retrieving revision 1.166 diff -u -p -r1.166 symtab.c --- gdb/symtab.c 9 Oct 2007 06:59:27 -0000 1.166 +++ gdb/symtab.c 18 Oct 2007 16:34:05 -0000 @@ -2267,10 +2267,10 @@ find_line_symtab (struct symtab *symtab, best_index = find_line_common (best_linetable, line, &exact); if (best_index < 0 || !exact) { - /* Didn't find an exact match. So we better keep looking for - another symtab with the same name. In the case of xcoff, - multiple csects for one source file (produced by IBM's FORTRAN - compiler) produce multiple symtabs (this is unavoidable + /* Didn't find an exact match, or any match. So we better keep + looking for another symtab with the same name. In the case of + xcoff, multiple csects for one source file (produced by IBM's + FORTRAN compiler) produce multiple symtabs (this is unavoidable assuming csects can be at arbitrary places in memory and that the GLOBAL_BLOCK of a symtab has a begin and end address). */ @@ -2411,6 +2411,9 @@ find_line_common (struct linetable *l, i int best_index = -1; int best = 0; + /* Assume an inexact match. */ + *exact_match = 0; + if (lineno <= 0) return -1; if (l == 0) @@ -2436,8 +2439,6 @@ find_line_common (struct linetable *l, i } /* If we got here, we didn't get an exact match. */ - - *exact_match = 0; return best_index; }