title: Safe coding practices in c : switching from dynamic to static memory allocation
body: <p>I'm working on embedded systems and my goal is to improve the safety of an existing code. I'm trying to follow Nasa's rules : <a href="https://en.wikipedia.org/wiki/The_Power_of_10:_Rules_for_Developing_Safety-Critical_Code" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/The_Power_of_10:_Rules_for_Developing_Safety-Critical_Code</a></p>
  <p>The existing code contains dynamically allocated instances and variables which is pretty common, I'm required to translate the program to static memory alocation.</p>
  <p><strong>Is there generic practices and patterns to succesfully switch from dynamic to static memory allocation without breaking the code ?</strong></p>
  <p>In particular, I'm having issues with those kinds of mallocs :</p>
  <pre class="lang-c prettyprint-override"><code>unsigned short int * residuals = NULL;
  residuals = (unsigned short int *)malloc(sizeof(unsigned short int)*input_params.x_size*input_params.y_size*input_params.z_size);
  
  // in a other file 
  
  block_samples[read_samples] = residuals[x + y*input_params.x_size + z*input_params.x_size*input_params.y_size]
  
  // something else i have trouble with : double pointers 
  predictor_params.weight_init_table = (int **)malloc(sizeof(int *)*input_params.z_size); 
  </code></pre>
  <p>I get segfaults when I try to statically allocates them with the following message in GDB :</p>
  <p><code>zero carry parity adjust sign trap INTERRUPT direction overflow RESUME virtualx86 identification</code></p>