rust: Fix null deref when casting (PR 23124)
authorDan Robertson <danlrobertson89@gmail.com>
Sat, 28 Apr 2018 03:18:00 +0000 (03:18 +0000)
committerTom Tromey <tom@tromey.com>
Tue, 1 May 2018 05:02:01 +0000 (23:02 -0600)
Fix a null dereference when casting a value to a unit type.

ChangeLog
2018-04-28  Dan Robertson  <danlrobertson89@gmail.com>

PR rust/23124
* gdb/rust-exp.y (convert_params_to_types): Ensure that the params
pointer is not null before dereferencing it.

testsuite/ChangeLog
2018-04-28  Dan Robertson  <danlrobertson89@gmail.com>

PR rust/23124
* gdb.rust/expr.exp: Test that the unit type is correctly parsed
when casting.

gdb/ChangeLog
gdb/rust-exp.y
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.rust/expr.exp

index 9c2264b0f4b265da85b39f1edac27e3a1aafbb45..85f7525a3ea1a1824ac008973087ca4fac5e4690 100644 (file)
@@ -1,3 +1,9 @@
+2018-04-28  Dan Robertson  <danlrobertson89@gmail.com>
+
+       PR rust/23124
+       * gdb/rust-exp.y (convert_params_to_types): Ensure that the params
+       pointer is not null before dereferencing it.
+
 2018-04-30  Tom Tromey  <tom@tromey.com>
 
        * darwin-nat-info.c (darwin_debug_regions_recurse): Remove use of
index 56aa689a08b7f6ff0a36b514291bc50361a94e38..9f21498d4c9aa5d5584189ac2ba76f349b8caabf 100644 (file)
@@ -2019,8 +2019,11 @@ convert_params_to_types (struct parser_state *state, rust_op_vector *params)
 {
   std::vector<struct type *> result;
 
-  for (const rust_op *op : *params)
-    result.push_back (convert_ast_to_type (state, op));
+  if (params != nullptr)
+    {
+      for (const rust_op *op : *params)
+        result.push_back (convert_ast_to_type (state, op));
+    }
 
   return result;
 }
index 4e48934cbf0429e3f1b7f7f7a18cbc56fbd98df2..cb5e6d02f851da0da798dc460af10a25ab347b6c 100644 (file)
@@ -1,3 +1,9 @@
+2018-04-28  Dan Robertson  <danlrobertson89@gmail.com>
+
+       PR rust/23124
+       * gdb.rust/expr.exp: Test that the unit type is correctly parsed
+       when casting.
+
 2018-04-30  Tom Tromey  <tom@tromey.com>
 
        * gdb.python/py-type.exp: Check align attribute.
index 0bc0630854415f3bcd2b0f651db88330657b3333..22e6b49b5421468ef28534134962b7e875a7cc73 100644 (file)
@@ -133,7 +133,9 @@ gdb_test "print \[23usize; 4\]" " = \\\[23, 23, 23, 23\\\]"
 gdb_test "ptype \[23usize; 4\]" " = \\\[usize; 4\\\]"
 gdb_test "print \[mut 23usize; 4\]" " = \\\[23, 23, 23, 23\\\]"
 
-# Test a lexer corner case.
+# Test lexer corner cases.
+gdb_test "print 0x0 as *const ()" " = \\\(\\\(\\\) \\*\\\) 0x0"
+gdb_test "print 0x0 as fn(i64) -> ()" " = \\\(\\\(\\\) \\\(\\*\\\)\\\(i64\\\)\\\) 0x0"
 gdb_test "print r#" "syntax error in expression, near `#'\\."
 
 gdb_test "printf \"%d %d\\n\", 23+1, 23-1" "24 22"
This page took 0.033791 seconds and 4 git commands to generate.