This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

[RFA:] Fix two uninitialized-bugs in cppexp.c spotted by valgrind


Most valgrind-indications for C were caused by the bugs Honza and Andreas
Jaeger fixed.  There are a few odd cases bootstrapping non-C, for example
Java and g77 (at least a few weeks ago) and a few found by the test-suite.

Here are fixes for two of them, applicable for "any target" (MMIX and host
i686-pc-linux-gnu), executing (for example) for:

num_part_mul: gcc.dg/cpp/arith-1.c
==28741== Conditional jump or move depends on uninitialised value(s)
==28741==    at 0x809C579: num_negate (cppexp.c:1113)
==28741==    by 0x809D128: num_mul (cppexp.c:1470)
==28741==    by 0x809C02F: reduce (cppexp.c:920)
==28741==    by 0x809BCD4: _cpp_parse_expr (cppexp.c:792)

and for eval_token: gcc.dg/cpp/assert2.c.
==28727== Conditional jump or move depends on uninitialised value(s)
==28727==    at 0x80958B3: push_conditional (cpplib.c:1533)
==28727==    by 0x80955C2: do_if (cpplib.c:1413)
==28727==    by 0x8093FD8: _cpp_handle_directive (cpplib.c:440)
==28727==    by 0x8097177: _cpp_lex_token (cpplex.c:848)
==28727==
==28727== Conditional jump or move depends on uninitialised value(s)
==28727==    at 0x80940E9: _cpp_handle_directive (cpplib.c:412)
==28727==    by 0x8097177: _cpp_lex_token (cpplex.c:848)
==28727==    by 0x809A1D8: cpp_get_token (cppmacro.c:1121)
==28727==    by 0x80A1E88: scan_translation_unit (cppmain.c:146)

Bootstrapped and checked i686-pc-linux-gnu (non-valgrind), including
testing "manually" that valgrind complained about gcc.dg/cpp/arith-1.c and
gcc.dg/cpp/assert2.c without the patch, but not with the patch.

Ok to commit?

	* cppexp.c (num_part_mul): Initialize result.unsignedp, to 1.
	(eval_token): Initialize temp.

Index: cppexp.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppexp.c,v
retrieving revision 1.133
diff -p -c -r1.133 cppexp.c
*** cppexp.c	22 Sep 2002 02:03:16 -0000	1.133
--- cppexp.c	25 Nov 2002 06:27:51 -0000
*************** eval_token (pfile, token)
*** 607,612 ****
--- 607,615 ----
        break;

      default: /* CPP_HASH */
+       /* For recovery, an erroneous assertion expression is handled as a
+ 	 failing assertion.  */
+       temp = 0;
        _cpp_test_assertion (pfile, &temp);
        result.high = 0;
        result.low = temp;
*************** num_part_mul (lhs, rhs)
*** 1446,1451 ****
--- 1449,1455 ----

    result.high += HIGH_PART (middle[0]);
    result.high += HIGH_PART (middle[1]);
+   result.unsignedp = 1;

    return result;
  }

brgds, H-P


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