title: C - Cannot access memory at address
body: <p>When debugging GDB  tells me the following error:</p>
  
  <pre><code>0x800c99ed00000001 &lt; error: Cannot access memory at address 0x800c99ed00000001&gt;
  </code></pre>
  
  <p>The error is produced if I put a breakpoint when I call ConvertByteArrayToFloat while debugging .</p>
  
  <p>But the program exits without a problem and gives me an Ok result ?</p>
  
  <p>My main file:</p>
  
  <pre><code>#include "Local.h"
  
  int main(void) {
  
      if(HandleReceivedMessages() == OP_COMPLETED){
          printf("Main Completed \n" );
      } else {
          printf("Main Failed \n");
      }
      return 0;
  }
  </code></pre>
  
  <p>Local.h</p>
  
  <pre><code>#ifndef LOCAL_H_
  #define LOCAL_H_
  
  #include "Common.h"
  
  T_OP_STATUS HandleReceivedMessages(void);
  
  #endif
  </code></pre>
  
  <p>Local.c</p>
  
  <pre><code>#include "Handler.h"
  #include "Local.h"
  
  uint8_t message[] = {0x86, 0x9a, 0xa0, 0x00, 0x00, 0x01, 0x01, 0x07, 0x00, 0x10, 0x4a, 0x00, 0x00, 0x00, 0x00, 0xe1};
  
  uint8_t length = 16;
  
  T_OP_STATUS HandleReceivedMessages(void) {
  
      if(HandleResponseMessage(message, length) == STATUS_SUCCESS) {
          printf("Completed from Local \n");
          return OP_COMPLETED;
      } else {
          printf("Failed from Local \n");
          return OP_FAILED;
      }
  
  }
  </code></pre>
  
  <p>Handler.h</p>
  
  <pre><code>#ifndef HANDLER_H_
  #define HANDLER_H_
  
  #include "Common.h"
  
  T_MESSAGE_STATUS HandleResponseMessage(uint8_t *requestData, uint8_t msgLength);
  
  
  #endif /* HANDLER_H_ */
  </code></pre>
  
  <p>Handler.c</p>
  
  <pre><code>#include "Handler.h"
  #include &lt;string.h&gt;
  
  static uint8_t rawRequestData[BUFFER_WIRED_SIZE];
  
  static float TempFloat = 0;
  
  
  T_MESSAGE_STATUS HandleCmd(uint16_t cmdNumber, uint8_t rawDataLength,
                      uint8_t *rawDataPtr) {
  
      switch (cmdNumber) {
          case 1:
              TempFloat = ConvertByteArrayToFloat(&amp;rawDataPtr[3]);
              printf("The value of the float is : %f \n", TempFloat);
              return STATUS_SUCCESS;
          default:
              break;
      }
  
      return STATUS_NOT_IMPLEMENTED;
  }
  
  
  T_MESSAGE_STATUS HandleResponseMessage(uint8_t *message,
                                  uint8_t msgLength) {
  
      uint8_t cmdNumber, dataLength, startOfData;
  
  
      // Check the delimiter.
      if (message[0] &amp; INDICATOR_UNIQUE_ADDRESS) {
  
          cmdNumber = message[6];
          dataLength = message[7];
          startOfData = 8;
  
      } else {
  
          cmdNumber = message[2];
          dataLength = message[3];
          startOfData = 4;
      }
  
      // we copy only the real data from the command response
      memcpy(&amp;rawRequestData, message + startOfData, dataLength);
  
      return HandleCmd(cmdNumber, dataLength, rawRequestData);
  
  }
  </code></pre>
  
  <p>Common.h</p>
  
  <pre><code>#ifndef COMMON_H_
  #define COMMON_H_
  
  #include &lt;stdint.h&gt;
  #include &lt;stdio.h&gt;
  
  #define BUFFER_WIRED_SIZE               128
  #define INDICATOR_UNIQUE_ADDRESS        0x80
  
  
  typedef enum {
  
      OP_FAILED,
      OP_COMPLETED,
  
  }T_OP_STATUS;
  
  typedef enum
  {
      STATUS_SUCCESS,
      STATUS_NOT_IMPLEMENTED,
  
  } T_MESSAGE_STATUS;
  
  float ConvertByteArrayToFloat(uint8_t *data);
  
  
  #endif /* COMMON_H_ */
  </code></pre>
  
  <p>Common.c </p>
  
  <pre><code>#include "Common.h"
  
  float ConvertByteArrayToFloat(uint8_t *data) {
  
      union {
          uint8_t tmpArray[4];
          float tmpFloat;
     } value;
  
      value.tmpArray[0] = data[3];
      value.tmpArray[1] = data[2];
      value.tmpArray[2] = data[1];
      value.tmpArray[3] = data[0];
  
      return value.tmpFloat;
  }
  </code></pre>
  
  <p>This is the min version, (it does a lot of things like checking the format of the message, CRC, etc..)but goes from start to finish thru all those files. </p>
  
  <p>I am working on an embedded platform and when debugging in my microcontroller and calling the function ConvertByteArrayToFloat, my program jumps to some other part of my code and then it crashes the microcontroller. </p>
  
  <p>I try to recreate the error in my computer without the microcontroller and I found the error at the top. </p>