This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH] Pascal: Avoid possible division by zero in pascal_val_print.
- From: "Pierre Muller" <pierre dot muller at ics-cnrs dot unistra dot fr>
- To: <gdb-patches at sourceware dot org>
- Cc: "'Jan Kratochvil'" <jan dot kratochvil at redhat dot com>, "'Joost van der Sluis'" <joost at cnoc dot nl>, "'Jonas Maebe'" <jonas dot maebe at elis dot ugent dot be>
- Date: Thu, 20 May 2010 09:44:48 +0200
- Subject: [PATCH] Pascal: Avoid possible division by zero in pascal_val_print.
FYI, I committed the following patch
after a discussion with Jan Kratochvil, Joost van der Sluis
and Jonas Maebe about a possible division by zero
inside pascal_val_print code (for dynamic pascal arrays,
to be supported later).
The patch below removes that risk.
2010-05-20 Pierre Muller <muller@ics.u-strasbg.fr>
* p-valprint.c (pascal_val_print): Call get_array_bounds
to obtain the nmuber of elements in an array.
Index: src/gdb/p-valprint.c
===================================================================
RCS file: /cvs/src/src/gdb/p-valprint.c,v
retrieving revision 1.72
diff -u -p -r1.72 p-valprint.c
--- src/gdb/p-valprint.c 17 May 2010 15:29:02 -0000 1.72
+++ src/gdb/p-valprint.c 20 May 2010 07:33:20 -0000
@@ -60,6 +60,7 @@ pascal_val_print (struct type *type, con
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
unsigned int i = 0; /* Number of characters printed */
unsigned len;
+ long low_bound, high_bound;
struct type *elttype;
unsigned eltlen;
int length_pos, length_size, string_pos;
@@ -71,11 +72,11 @@ pascal_val_print (struct type *type, con
switch (TYPE_CODE (type))
{
case TYPE_CODE_ARRAY:
- if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) >
0)
+ if (get_array_bounds (type, &low_bound, &high_bound))
{
+ len = high_bound - low_bound + 1;
elttype = check_typedef (TYPE_TARGET_TYPE (type));
eltlen = TYPE_LENGTH (elttype);
- len = TYPE_LENGTH (type) / eltlen;
if (options->prettyprint_arrays)
{
print_spaces_filtered (2 + 2 * recurse, stream);