@@ -2302,7 +2302,7 @@ static struct expression
*check_designators(struct expression *e,
}
type = ctype->ctype.base_type;
if (ctype->bit_size >= 0 && type->bit_size >= 0) {
- unsigned offset = e->idx_to * type->bit_size;
+ unsigned offset =
array_element_offset(type->bit_size, e->idx_to);
if (offset >= ctype->bit_size) {
err = "index out of bounds in";
break;
@@ -234,7 +234,8 @@ static struct symbol * examine_array_type(struct
symbol *sym)
return sym;
if (array_size) {
- bit_size = base_type->bit_size *
get_expression_value_silent(array_size);
+ bit_size = array_element_offset(base_type->bit_size,
+
get_expression_value_silent(array_size));
if (array_size->type != EXPR_VALUE) {
if (Wvla)
warning(array_size->pos, "Variable
length array is used.");
@@ -57,4 +57,12 @@ static inline int bytes_to_bits(int bytes)
return bytes * bits_in_char;
}
+static inline unsigned long array_element_offset(unsigned long
base_bits, int idx)
+{
+ int fragment = base_bits % bits_in_char;
+ if (fragment)
+ base_bits += bits_in_char - fragment;
+ return base_bits * idx;
+}
+