Reputation: 47
The program will return a set of string "This is James: 00:00:00" and a time format but it crashed. I believe there is a missing memory allocation but couldn't pin where the error is.
FREObject result = 0;
uint32_t len = -1;
const uint8_t *str = 0;
char *temp;
uint8_t *strAll;
time_t curtime;
struct tm *loctime;
/* Get the current time. */
curtime = time(NULL);
/* Convert it to local time representation. */
loctime = localtime(&curtime);
//Turn our actionscrpt code into native code.
if(FREGetObjectAsUTF8(argv[0], &len, &str) == FRE_OK) {
temp = "Hello World! This is ";
strAll = (char *)malloc(sizeof(temp) + sizeof(str) + sizeof(loctime));
strcpy(strAll,temp);
strcat(strAll,str);
strcat(strAll,asctime(loctime));
}
Upvotes: 0
Views: 201
Reputation: 182639
You probably want strlen
instead of sizeof
here:
strAll = (char *)malloc(sizeof(temp) + sizeof(str) + sizeof(loctime));
Also the sizeof(loctime)
makes very little sense. You probably want to replace it with the length of asctime(loctime)
.
Maybe something like this:
char *asc = asctime(loctime);
strAll = malloc(strlen(temp) + strlen(str) + stren(asc) + 1);
Upvotes: 3