aboutsummaryrefslogtreecommitdiffstats
path: root/src/grt
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2018-08-06 07:52:11 +0200
committerTristan Gingold <tgingold@free.fr>2018-08-07 06:27:17 +0200
commitd62f20f969975166fc0a28198bb909ea0a7dec9a (patch)
tree7b4ee187fcc43e64028934b7d82e5a03bca10af9 /src/grt
parentb47d09862f3c05e8827ac5a39880a5303f3ba767 (diff)
downloadghdl-d62f20f969975166fc0a28198bb909ea0a7dec9a.tar.gz
ghdl-d62f20f969975166fc0a28198bb909ea0a7dec9a.tar.bz2
ghdl-d62f20f969975166fc0a28198bb909ea0a7dec9a.zip
ghwlib: handle correctly with null-range. For #615
Diffstat (limited to 'src/grt')
-rw-r--r--src/grt/ghwlib.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/src/grt/ghwlib.c b/src/grt/ghwlib.c
index 99d72d021..0e3a07568 100644
--- a/src/grt/ghwlib.c
+++ b/src/grt/ghwlib.c
@@ -483,27 +483,36 @@ get_nbr_elements (union ghw_type *t)
int
ghw_get_range_length (union ghw_range *rng)
{
+ int res;
+
+ assert (rng != NULL);
+
switch (rng->kind)
{
case ghdl_rtik_type_i32:
if (rng->i32.dir)
- return (rng->i32.left - rng->i32.right + 1);
+ res = rng->i32.left - rng->i32.right + 1;
else
- return (rng->i32.right - rng->i32.left + 1);
+ res = rng->i32.right - rng->i32.left + 1;
+ break;
case ghdl_rtik_type_b2:
if (rng->b2.dir)
- return (rng->b2.left - rng->b2.right + 1);
+ res = rng->b2.left - rng->b2.right + 1;
else
- return (rng->b2.right - rng->b2.left + 1);
+ res = rng->b2.right - rng->b2.left + 1;
+ break;
case ghdl_rtik_type_e8:
if (rng->e8.dir)
- return (rng->e8.left - rng->e8.right + 1);
+ res = rng->e8.left - rng->e8.right + 1;
else
- return (rng->e8.right - rng->e8.left + 1);
+ res = rng->e8.right - rng->e8.left + 1;
+ break;
default:
fprintf (stderr, "get_range_length: unhandled kind %d\n", rng->kind);
abort ();
}
+ /* The length of a null range is 0. */
+ return (res <= 0) ? 0 : res;
}
/* Create an array subtype using BASE and ranges read from H. */
@@ -673,15 +682,15 @@ ghw_read_type (struct ghw_handler *h)
ph->nbr_units = 0;
else
{
- unsigned i;
+ unsigned j;
if (ghw_read_uleb128 (h, &ph->nbr_units) != 0)
goto err_p32;
ph->units = malloc (ph->nbr_units * sizeof (struct ghw_unit));
- for (i = 0; i < ph->nbr_units; i++)
+ for (j = 0; j < ph->nbr_units; j++)
{
- ph->units[i].name = ghw_read_strid (h);
- if (ghw_read_lsleb128 (h, &ph->units[i].val) < 0)
+ ph->units[j].name = ghw_read_strid (h);
+ if (ghw_read_lsleb128 (h, &ph->units[j].val) < 0)
goto err_p32;
}
}
@@ -1203,6 +1212,9 @@ print_name (struct ghw_hie *hie, int full_names)
struct ghw_hie **buf;
struct ghw_hie **end;
+ /* HIE must be valid. */
+ assert (hie->name != NULL);
+
if (0 == full_names)
{
printf (" %s: ", hie->name);