Skip to content

Commit

Permalink
[Coverity] Use snprintf instead of sprintf
Browse files Browse the repository at this point in the history
Let's use safer form of the sprintf() function.

Signed-off-by: gichan2-jang <[email protected]>
  • Loading branch information
gichan-jang authored and jaeyun-jung committed Sep 12, 2023
1 parent 9d22cdd commit f96cb9f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions c/src/ml-api-remote-service.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "ml-api-service.h"
#include "ml-api-service-private.h"

#define MAX_PORT_NUM_LEN 6U

/**
* @brief Data struct for options.
*/
Expand Down Expand Up @@ -114,17 +116,17 @@ _mlrs_get_edge_info (ml_option_h option, edge_info_s * edge_info)
static void
_mlrs_set_edge_info (edge_info_s * edge_info, nns_edge_h edge_h)
{
char port[6];
char port[MAX_PORT_NUM_LEN] = { 0, };

nns_edge_set_info (edge_h, "HOST", edge_info->host);
sprintf (port, "%u", edge_info->port);
g_snprintf (port, MAX_PORT_NUM_LEN, "%u", edge_info->port);
nns_edge_set_info (edge_h, "PORT", port);

if (edge_info->topic)
nns_edge_set_info (edge_h, "TOPIC", edge_info->topic);

nns_edge_set_info (edge_h, "DEST_HOST", edge_info->dest_host);
sprintf (port, "%u", edge_info->dest_port);
g_snprintf (port, MAX_PORT_NUM_LEN, "%u", edge_info->dest_port);
nns_edge_set_info (edge_h, "DEST_PORT", port);
}

Expand Down

0 comments on commit f96cb9f

Please sign in to comment.