diff options
Diffstat (limited to 'src/grt')
-rw-r--r-- | src/grt/ghwlib.c | 32 |
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); |