I am writing a code to run in TI chip and my code gets stuck during the following code
UChar* message;
UChar* tempMessage;
message = malloc( bytesOfMessage * sizeof(UChar));
int i = 0;
while(true)
{
int rxBytes = UART_read(handle, rxBuf, 1);
//System_printf("%d \n", rxBuf[0]);
if(rxBuf[0] != 13)
{
message[i] = rxBuf[0];
i++;
int l = 1;
if(i == bytesOfMessage)
{
System_printf("first Message: \n");
for(l=0;l<bytesOfMessage;l++)
{
//System_printf("%c",message[l]);
}
System_printf("End of first Message\n");
bytesOfMessage += 10;
//message = realloc(message, bytesOfMessage * sizeof(UChar));
tempMessage = (UChar*)realloc(message, bytesOfMessage * sizeof(UChar));
message = tempMessage;
tempMessage = NULL;
System_printf("Message2 %d: \n", bytesOfMessage);
for(l=0;l<bytesOfMessage;l++)
{
//System_printf("%c", message[l]);
}
System_printf("End of second Message\n");
}
UART_write(handle, rxBuf, rxBytes);
}
else
{
rxBuf[0] = '\r';
rxBuf[1] = '\n';
rxBuf[2] = 'n';
rxBuf[3] = 'e';
rxBuf[4] = 'w';
UART_write(handle, rxBuf, 5);
}
}
It really doesnt matter what UART_read does.
but the important thing is the realloc function.
the first time I get to that code it's doing OK. But the second time it just gets stuck. Is it a normal code that is supposed to work and the problem is with the chip or the operating system??