I have two functions.
struct logger_message vget_log_msg(enum LogStatus log_status, const char* format, va_list args) {
struct logger_message log_msg;
log_msg.status = log_status;
log_msg.timestamp = get_current_timestamp();
memset(log_msg.message_buffer, 0, MESSAGE_SIZE);
if(format){
vsprintf(log_msg.message_buffer, format, args);
}
return log_msg;
}
and
int send_log_message_to_mqueue(mqd_t mqd, enum LogStatus log_status, const char* format, ...) {
struct logger_message msg;
va_list argp;
va_start(argp, format);
msg = vget_log_msg(log_status, format, argp);
va_end(argp);
int res;
res = send_message_to_mqueue(mqd, (char *)&msg, sizeof(msg));
return res;
}
So, I get the error “Segmentation Fault(Core dumped)” while returning from vget_log_msg on line:
msg = vget_log_msg(log_status, format, argp);
EDIT: Maybe this information can be useful
struct logger_message{
enum LogStatus status;
time_t timestamp;
char message_buffer[MESSAGE_SIZE];
};
Does anybody know why I get this error? how to correct it?
What is MESSAGE_SIZE? how big is that? Can you check by reducing the size of it, or instead return using pointer instead of the whole structure.