This is the mail archive of the gdb-patches@sources.redhat.com 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]

Trivial fix in value_sub


In value_sub, if you are doing pointer - integer and pointer points to 
an incomplete type,
then the computation:

ptr - sizeof (*ptr) * integer

turns into just:

ptr

which is probably not what the user expected.  In value_add, the return 
from TYPE_LENGTH is checked for zero, and set to 1 if it is.  We should 
probably do the same thing for value_sub, a la:

2002-03-29  James Ingham  <jingham@apple.com>

         * valarith.c (value_sub): If you are doing pointer - integer,
         and TYPE_LENGTH of the pointer's target comes back 0, set it
         to 1.  This is what value_add does, and we should be consistent.

Index: valarith.c
===================================================================
RCS file: /cvs/src/src/gdb/valarith.c,v
retrieving revision 1.14
diff -c -w -r1.14 valarith.c
*** valarith.c  2002/03/27 21:35:35     1.14
--- valarith.c  2002/03/29 23:22:27
***************
*** 105,110 ****
--- 105,112 ----
         {
           /* pointer - integer.  */
           LONGEST sz = TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE 
(type1)));
+         if (sz == 0)
+           sz = 1;
           return value_from_pointer (type1,
                                      (value_as_address (arg1)
                                       - (sz * value_as_long (arg2))));

Jim
--
Jim Ingham                                   jingham@apple.com
Developer Tools - gdb
Apple Computer


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