title: Incomplete pointer array to struct. Stack smashing detected
body: <p>My apologies in advance for the bad-looking code. It's just a proof of concept.</p>
  <p>The purpose of the program is to fill the &quot;datapacket&quot;, but by individually accessible pointers of the <code>potmeter</code> struct.</p>
  <p>The program works with a complete type of <code>*potPointers[3]</code>. It also works with incomplete type <code>*potPointer[]</code>. But then after a successful run, I get:</p>
  <pre>
  *** stack smashing detected ***: terminated
  Aborted (core dumped)
  </pre>
  <p>How do I successfully deal with incomplete pointer arrays to a struct?
  I can of course put a <code>#define</code>, but is there another way?</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdint.h&gt;
  #include &lt;stdlib.h&gt;
  
  #define BYTES_DATAWORD_POTMETER 2
  
  typedef struct
  {
      uint8_t test;
      uint8_t *datawordPointer[2];
  }potmeter;
  
  typedef struct
  {
      uint8_t amountOfPots;
  
      size_t datapacket_size;
      uint8_t *datapacket; // needs to be malloc'ed, don't forget to free it.
      
      // Sort of working with *** stack smashing detected ***: terminated Aborted (core dumped)         
      potmeter *potPointers[];
  
     // Works without stack smashing.
     // potmeter *potPointers[3];     
       
  }overall;
  
  
  void initPointersToDatapackett(overall *allePots)
  { 
      uint8_t counter = 0;
  
      for(int i = 0; i &lt; allePots-&gt;amountOfPots; i++)
      {
          // Allocate memory per pot
          allePots-&gt;potPointers[i] = malloc(sizeof(potmeter));
  
          // Point pointers to dataword of overall
          allePots-&gt;potPointers[i]-&gt;datawordPointer[0] = &amp;allePots-&gt;datapacket[counter++];
          allePots-&gt;potPointers[i]-&gt;datawordPointer[1] = &amp;allePots-&gt;datapacket[counter++];
          
      }
  }
  
  
  
  int main()
  {
      overall AllePotMeters;
  
      AllePotMeters.amountOfPots = 3;
      AllePotMeters.datapacket = malloc(AllePotMeters.amountOfPots*BYTES_DATAWORD_POTMETER);
      
  
      initPointersToDatapackett(&amp;AllePotMeters);
  
      //Test content of pointers to dataword
      *AllePotMeters.potPointers[0]-&gt;datawordPointer[0] = 'A';
      *AllePotMeters.potPointers[0]-&gt;datawordPointer[1] = 'B';
      *AllePotMeters.potPointers[1]-&gt;datawordPointer[0] = 'C';
      *AllePotMeters.potPointers[1]-&gt;datawordPointer[1] = 'D';
      *AllePotMeters.potPointers[2]-&gt;datawordPointer[0] = 'E';
      *AllePotMeters.potPointers[2]-&gt;datawordPointer[1] = '\0';
  
  
      printf(&quot;String test %s\n&quot;, AllePotMeters.datapacket);
  
  
      free(AllePotMeters.potPointers[0]);
      free(AllePotMeters.potPointers[1]);
      free(AllePotMeters.potPointers[2]);
      free(AllePotMeters.datapacket);
  
      return 0;
  }
  
  </code></pre>