简体   繁体   English

返回time_t错误

[英]return time_t error

The program will return a set of string "This is James: 00:00:00" and a time format but it crashed. 该程序将返回一组字符串“ This is James:00:00:00”和一个时间格式,但是它崩溃了。 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));
}

You probably want strlen instead of sizeof here: 你可能想strlen代替sizeof这里:

strAll = (char *)malloc(sizeof(temp) + sizeof(str) + sizeof(loctime));

Also the sizeof(loctime) makes very little sense . 同样, sizeof(loctime)毫无意义 You probably want to replace it with the length of asctime(loctime) . 您可能希望将其替换为asctime(loctime)的长度。

Maybe something like this: 也许是这样的:

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