From 3a1fc260f01d38b733dc4e7941cb3172dfdf6d01 Mon Sep 17 00:00:00 2001 From: cmoller Date: Mon, 8 Feb 2010 18:27:53 +0000 Subject: PR gdb/10728 * valarith.c (value_ptrdiff): Added a test for a zero type length, warn if found, and assume length = 1. * gdb.cp/pr10728-x.h: New file. * gdb.cp/pr10728-x.cc: New file. * gdb.cp/pr10728-y.cc: New file. * gdb.cp/pr10728.exp: New file. * gdb.cp/Makefile.in (EXECUTABLES): Add pr10728 --- gdb/valarith.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'gdb/valarith.c') diff --git a/gdb/valarith.c b/gdb/valarith.c index ed76b0960ba..c87bc6f255e 100644 --- a/gdb/valarith.c +++ b/gdb/valarith.c @@ -122,6 +122,13 @@ First argument of `-' is a pointer and second argument is neither\n\ an integer nor a pointer of the same type.")); sz = TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type1))); + if (sz == 0) + { + warning (_("Type size unknown, assuming 1. " + "Try casting to a known type, or void *.")); + sz = 1; + } + return (value_as_long (arg1) - value_as_long (arg2)) / sz; } -- cgit v1.2.1