Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* Trivial fix in value_sub
@ 2002-03-29 15:27 Jim Ingham
  2002-04-03 14:52 ` Jim Blandy
  0 siblings, 1 reply; 11+ messages in thread
From: Jim Ingham @ 2002-03-29 15:27 UTC (permalink / raw)
  To: gdb-patches

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


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2002-04-10  0:12 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-29 15:27 Trivial fix in value_sub Jim Ingham
2002-04-03 14:52 ` Jim Blandy
2002-04-03 15:55   ` Michael Snyder
2002-04-03 16:11   ` Jim Ingham
2002-04-03 19:55     ` Jim Blandy
2002-04-03 20:11       ` Daniel Jacobowitz
2002-04-04 13:46         ` Jim Ingham
2002-04-04 14:24           ` Jim Blandy
2002-04-04 15:07             ` Jim Ingham
2002-04-04 15:15               ` Jim Blandy
2002-04-09 17:12                 ` Jim Ingham

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox