VC 解决 函数调用报错:未经处理的异常: 0xC00000FD: Stack overflow (参数: 0x00000000, 0x06442000)。

#define LOGGER_MSG_BUF_SIZE 102400
#define LOG(format, ...){\
	char msg[LOGGER_MSG_BUF_SIZE]={0};\
	time_t t;\
	struct tm *tm;\
	t = time(NULL);\
	tm = localtime(&t);\
	SNPRINTF(msg, LOGGER_MSG_BUF_SIZE, "%04d-%02d-%02d %02d:%02d:%02d [libahdmsUkey] DEBUG: "format" %s(%s:%d)\n", tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, ##__VA_ARGS__, __FUNCTION__, __FILE__, __LINE__);\
	msg[LOGGER_MSG_BUF_SIZE -2] = '\n';\
	msg[LOGGER_MSG_BUF_SIZE -1] = '\0';\
	logger_writeLog(msg, strlen(msg));\
	}

参考上述代码,调用的函数有调用LOG宏记录日志,而日志内容缓冲区msg占用 102400,导致程序崩溃。


调整代码如下:


#define LOGGER_MSG_BUF_SIZE 1024
#define LOG(format, ...){\
	char msg[LOGGER_MSG_BUF_SIZE]={0};\
	time_t t;\
	struct tm *tm;\
	t = time(NULL);\
	tm = localtime(&t);\
	SNPRINTF(msg, LOGGER_MSG_BUF_SIZE, "%04d-%02d-%02d %02d:%02d:%02d [libahdmsUkey] DEBUG: "format" %s(%s:%d)\n", tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, ##__VA_ARGS__, __FUNCTION__, __FILE__, __LINE__);\
	msg[LOGGER_MSG_BUF_SIZE -2] = '\n';\
	msg[LOGGER_MSG_BUF_SIZE -1] = '\0';\
	logger_writeLog(msg, strlen(msg));\
	}


你可能感兴趣的:(VC 解决 函数调用报错:未经处理的异常: 0xC00000FD: Stack overflow (参数: 0x00000000, 0x06442000)。)