Skip to content

Commit

Permalink
Rewrite snprintf usage
Browse files Browse the repository at this point in the history
  • Loading branch information
arnd-s authored and Kaian committed Oct 20, 2020
1 parent 36376de commit 50810af
Showing 1 changed file with 13 additions and 22 deletions.
35 changes: 13 additions & 22 deletions src/curses/ui_call_flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ call_flow_draw_message(ui_t *ui, call_flow_arrow_t *arrow, int cline)
char msg_time[80];
address_t src;
address_t dst;
char method[METHOD_MAXLEN];
char method[METHOD_MAXLEN + 1];
char delta[15] = {};
int flowh, floww;
char mediastr[40];
Expand All @@ -436,6 +436,9 @@ call_flow_draw_message(ui_t *ui, call_flow_arrow_t *arrow, int cline)
int msglen;
int aline = cline + 1;

// Initialize method
memset(method, 0, sizeof(method));

// Get panel information
info = call_flow_info(ui);

Expand All @@ -462,45 +465,33 @@ call_flow_draw_message(ui_t *ui, call_flow_arrow_t *arrow, int cline)
timeval_to_time(msg_get_time(msg), msg_time);

// Get Message method (include extra info)
if (METHOD_MAXLEN <= (snprintf(method, METHOD_MAXLEN, "%s", msg_method))) {
method[METHOD_MAXLEN-1]='\0';
}
snprintf(method, METHOD_MAXLEN, "%s", msg_method);

// If message has sdp information
if (msg_has_sdp(msg) && setting_has_value(SETTING_CF_SDP_INFO, "off")) {
// Show sdp tag in title
if (METHOD_MAXLEN <= (snprintf(method, METHOD_MAXLEN, "%s (SDP)", msg_method))) {
method[METHOD_MAXLEN-1]='\0';
}
snprintf(method, METHOD_MAXLEN, "%s (SDP)", msg_method );
}

// If message has sdp information
if (setting_has_value(SETTING_CF_SDP_INFO, "compressed")) {
// Show sdp tag in title
if (msg_has_sdp(msg)) {
if (METHOD_MAXLEN <= (snprintf(method, METHOD_MAXLEN, "%.*s (SDP)", 12, msg_method))) {
method[METHOD_MAXLEN-1]='\0';
}
snprintf(method, METHOD_MAXLEN, "%.*s (SDP)", 12, msg_method);
} else {
if (METHOD_MAXLEN <= (snprintf(method, METHOD_MAXLEN, "%.*s", 17, msg_method))) {
method[METHOD_MAXLEN-1]='\0';
}
snprintf(method, METHOD_MAXLEN, "%.*s", 17, msg_method);
}
}

if (msg_has_sdp(msg) && setting_has_value(SETTING_CF_SDP_INFO, "first")) {
if (METHOD_MAXLEN <= (snprintf(method, METHOD_MAXLEN, "%.3s (%s:%u)",
msg_method,
media->address.ip,
media->address.port))) {
method[METHOD_MAXLEN-1]='\0';
}
snprintf(method, METHOD_MAXLEN, "%.3s (%s:%u)",
msg_method,
media->address.ip,
media->address.port);
}

if (msg_has_sdp(msg) && setting_has_value(SETTING_CF_SDP_INFO, "full")) {
if (METHOD_MAXLEN <= (snprintf(method, METHOD_MAXLEN, "%.3s (%s)", msg_method, media->address.ip))) {
method[METHOD_MAXLEN-1]='\0';
}
snprintf(method, METHOD_MAXLEN, "%.3s (%s)", msg_method, media->address.ip);
}

// Draw message type or status and line
Expand Down

0 comments on commit 50810af

Please sign in to comment.