簡體   English   中英

返回time_t錯誤

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM