[英]return time_t error
該程序將返回一組字符串“ This is James:00:00:00”和一個時間格式,但是它崩潰了。 我認為內存分配丟失,但是無法固定錯誤所在。
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));
}
你可能想strlen
代替sizeof
這里:
strAll = (char *)malloc(sizeof(temp) + sizeof(str) + sizeof(loctime));
同樣, sizeof(loctime)
毫無意義 。 您可能希望將其替換為asctime(loctime)
的長度。
也許是這樣的:
char *asc = asctime(loctime);
strAll = malloc(strlen(temp) + strlen(str) + stren(asc) + 1);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.