Uploaded image for project: 'Embedded Software & Tools'
  1. Embedded Software & Tools
  2. EXT_EP-10637

Incorrect initialization of implicitly-sized array from constant initialization value with designated initializers

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Medium Medium

      The attached file.c has these lines ...

      typedef struct {
          unsigned a;
          unsigned b;
      } entry_t;
      
      typedef struct {
          unsigned len;
          entry_t entries[];
      } array_t;
      
      const array_t array = {
        .len = 3,
        .entries = {
                  { .a = 1,},
                  { .a = 2},
                  { .a = 3},
        },
      };
      

      Build it ...

      % cl2000 -s file.c
      

      Inspect the resulting assembly file ...

      _array:
              .bits           0x3,16
                              ; _array._len @ 0
              .bits           0x1,16
                              ; _array[0]._a @ 16
              .space  16
              .bits           0x2,16
                              ; _array[1]._a @ 48
              .space  16
              .bits           0x3,16
                              ; _array[2]._a @ 80
      

      There should be one more line of ".space 16", so that array[3].b is set to 0. Instead it ends up having the value of whatever is next in memory.

            syncuser TI User
            syncuser TI User
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: