replace snprintf with strlcpy without adding extra include
authorBruce Richardson <bruce.richardson@intel.com>
Wed, 3 Apr 2019 14:45:04 +0000 (15:45 +0100)
committerThomas Monjalon <thomas@monjalon.net>
Thu, 4 Apr 2019 20:45:54 +0000 (22:45 +0200)
For files that already have rte_string_fns.h included in them, we can
do a straight replacement of snprintf(..."%s",...) with strlcpy. The
changes in this patch were auto-generated via command:

spatch --sp-file devtools/cocci/strlcpy-with-header.cocci --dir . --in-place

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
47 files changed:
app/pdump/main.c
app/proc-info/main.c
app/test-bbdev/main.c
app/test/test_cmdline_etheraddr.c
app/test/test_cmdline_num.c
app/test/test_compressdev.c
app/test/test_eal_flags.c
drivers/bus/pci/bsd/pci.c
drivers/bus/vdev/vdev.c
drivers/net/bonding/rte_eth_bond_pmd.c
drivers/net/dpaa2/dpaa2_ethdev.c
drivers/net/failsafe/failsafe_args.c
drivers/net/i40e/i40e_ethdev.c
drivers/net/pcap/rte_eth_pcap.c
drivers/net/ring/rte_eth_ring.c
drivers/net/softnic/rte_eth_softnic_tap.c
drivers/net/tap/rte_eth_tap.c
examples/cmdline/commands.c
examples/cmdline/parse_obj_list.c
examples/exception_path/main.c
examples/ip_pipeline/kni.c
examples/ip_pipeline/tap.c
examples/l3fwd-power/main.c
examples/multi_process/simple_mp/mp_commands.c
examples/netmap_compat/bridge/bridge.c
examples/netmap_compat/lib/compat_netmap.c
examples/tep_termination/main.c
examples/vhost/main.c
examples/vhost_scsi/scsi.c
lib/librte_cmdline/cmdline.c
lib/librte_cmdline/cmdline_parse.c
lib/librte_cmdline/cmdline_parse_num.c
lib/librte_cryptodev/rte_cryptodev.c
lib/librte_distributor/rte_distributor.c
lib/librte_distributor/rte_distributor_v20.c
lib/librte_eal/common/eal_common_memzone.c
lib/librte_eal/common/eal_common_tailqs.c
lib/librte_ethdev/rte_ethdev.c
lib/librte_hash/rte_cuckoo_hash.c
lib/librte_hash/rte_fbk_hash.c
lib/librte_kni/rte_kni.c
lib/librte_lpm/rte_lpm.c
lib/librte_lpm/rte_lpm6.c
lib/librte_mempool/rte_mempool.c
lib/librte_pdump/rte_pdump.c
lib/librte_pipeline/rte_pipeline.c
lib/librte_ring/rte_ring.c

index ccf2a1d..ae0cf28 100644 (file)
@@ -189,12 +189,12 @@ parse_rxtxdev(const char *key, const char *value, void *extra_args)
        struct pdump_tuples *pt = extra_args;
 
        if (!strcmp(key, PDUMP_RX_DEV_ARG)) {
-               snprintf(pt->rx_dev, sizeof(pt->rx_dev), "%s", value);
+               strlcpy(pt->rx_dev, value, sizeof(pt->rx_dev));
                /* identify the tx stream type for pcap vdev */
                if (if_nametoindex(pt->rx_dev))
                        pt->rx_vdev_stream_type = IFACE;
        } else if (!strcmp(key, PDUMP_TX_DEV_ARG)) {
-               snprintf(pt->tx_dev, sizeof(pt->tx_dev), "%s", value);
+               strlcpy(pt->tx_dev, value, sizeof(pt->tx_dev));
                /* identify the tx stream type for pcap vdev */
                if (if_nametoindex(pt->tx_dev))
                        pt->tx_vdev_stream_type = IFACE;
index b9acfa9..3cd5341 100644 (file)
@@ -193,7 +193,7 @@ proc_info_preparse_args(int argc, char **argv)
                                proc_info_usage(prgname);
                                return -1;
                        }
-                       snprintf(host_id, sizeof(host_id), "%s", argv[i+1]);
+                       strlcpy(host_id, argv[i + 1], sizeof(host_id));
                }
        }
 
index 7af2522..a2f8722 100644 (file)
@@ -226,9 +226,8 @@ parse_args(int argc, char **argv, struct test_params *tp)
                        TEST_ASSERT(strlen(optarg) > 0,
                                        "Config file name is null");
 
-                       snprintf(tp->test_vector_filename,
-                                       sizeof(tp->test_vector_filename),
-                                       "%s", optarg);
+                       strlcpy(tp->test_vector_filename, optarg,
+                               sizeof(tp->test_vector_filename));
                        break;
                case 'l':
                        TEST_ASSERT(strlen(optarg) > 0,
index 6ceba4b..086108a 100644 (file)
@@ -118,8 +118,7 @@ test_parse_etheraddr_invalid_param(void)
        /* try null result */
 
        /* copy string to buffer */
-       snprintf(buf, sizeof(buf), "%s",
-                       ether_addr_valid_strs[0].str);
+       strlcpy(buf, ether_addr_valid_strs[0].str, sizeof(buf));
 
        ret = cmdline_parse_etheraddr(NULL, buf, NULL, 0);
        if (ret == -1) {
index ea6b9f1..4c97caf 100644 (file)
@@ -318,8 +318,7 @@ test_parse_num_invalid_param(void)
        token.num_data.type = UINT32;
 
        /* copy string to buffer */
-       snprintf(buf, sizeof(buf), "%s",
-                       num_valid_positive_strs[0].str);
+       strlcpy(buf, num_valid_positive_strs[0].str, sizeof(buf));
 
        /* try all null */
        ret = cmdline_parse_num(NULL, NULL, NULL, 0);
index 13cf26c..ae9fc83 100644 (file)
@@ -767,7 +767,7 @@ test_deflate_comp_decomp(const struct interim_data_params *int_data,
                for (i = 0; i < num_bufs; i++) {
                        data_size = strlen(test_bufs[i]) + 1;
                        buf_ptr = rte_pktmbuf_append(uncomp_bufs[i], data_size);
-                       snprintf(buf_ptr, data_size, "%s", test_bufs[i]);
+                       strlcpy(buf_ptr, test_bufs[i], data_size);
                }
        }
 
index d626dd7..9112c96 100644 (file)
@@ -58,7 +58,7 @@ get_hugepage_path(char * src, int src_len, char * dst, int dst_len)
                return 0;
 
        if (strncmp(tokens[2], "hugetlbfs", sizeof("hugetlbfs")) == 0) {
-               snprintf(dst, dst_len, "%s", tokens[1]);
+               strlcpy(dst, tokens[1], dst_len);
                return 1;
        }
        return 0;
index d09f8ee..c7b90cb 100644 (file)
@@ -145,7 +145,7 @@ pci_uio_alloc_resource(struct rte_pci_device *dev,
                goto error;
        }
 
-       snprintf((*uio_res)->path, sizeof((*uio_res)->path), "%s", devname);
+       strlcpy((*uio_res)->path, devname, sizeof((*uio_res)->path));
        memcpy(&(*uio_res)->pci_addr, &dev->addr, sizeof((*uio_res)->pci_addr));
 
        return 0;
index 87f0e2b..04f76a6 100644 (file)
@@ -192,7 +192,7 @@ alloc_devargs(const char *name, const char *args)
        else
                devargs->args = strdup("");
 
-       ret = snprintf(devargs->name, sizeof(devargs->name), "%s", name);
+       ret = strlcpy(devargs->name, name, sizeof(devargs->name));
        if (ret < 0 || ret >= (int)sizeof(devargs->name)) {
                free(devargs->args);
                free(devargs);
index 154257f..f30422a 100644 (file)
@@ -493,27 +493,27 @@ arp_op_name(uint16_t arp_op, char *buf, size_t buf_len)
 {
        switch (arp_op) {
        case ARP_OP_REQUEST:
-               snprintf(buf, buf_len, "%s", "ARP Request");
+               strlcpy(buf, "ARP Request", buf_len);
                return;
        case ARP_OP_REPLY:
-               snprintf(buf, buf_len, "%s", "ARP Reply");
+               strlcpy(buf, "ARP Reply", buf_len);
                return;
        case ARP_OP_REVREQUEST:
-               snprintf(buf, buf_len, "%s", "Reverse ARP Request");
+               strlcpy(buf, "Reverse ARP Request", buf_len);
                return;
        case ARP_OP_REVREPLY:
-               snprintf(buf, buf_len, "%s", "Reverse ARP Reply");
+               strlcpy(buf, "Reverse ARP Reply", buf_len);
                return;
        case ARP_OP_INVREQUEST:
-               snprintf(buf, buf_len, "%s", "Peer Identify Request");
+               strlcpy(buf, "Peer Identify Request", buf_len);
                return;
        case ARP_OP_INVREPLY:
-               snprintf(buf, buf_len, "%s", "Peer Identify Reply");
+               strlcpy(buf, "Peer Identify Reply", buf_len);
                return;
        default:
                break;
        }
-       snprintf(buf, buf_len, "%s", "Unknown");
+       strlcpy(buf, "Unknown", buf_len);
        return;
 }
 #endif
index 3fbc829..c4f3a2b 100644 (file)
@@ -1334,10 +1334,9 @@ dpaa2_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
 
        if (xstats_names != NULL)
                for (i = 0; i < stat_cnt; i++)
-                       snprintf(xstats_names[i].name,
-                                sizeof(xstats_names[i].name),
-                                "%s",
-                                dpaa2_xstats_strings[i].name);
+                       strlcpy(xstats_names[i].name,
+                               dpaa2_xstats_strings[i].name,
+                               sizeof(xstats_names[i].name));
 
        return stat_cnt;
 }
index c4b220c..3351c5b 100644 (file)
@@ -102,7 +102,7 @@ fs_execute_cmd(struct sub_device *sdev, char *cmdline)
                        ERROR("Command line allocation failed");
                        return -ENOMEM;
                }
-               snprintf(sdev->cmdline, len, "%s", cmdline);
+               strlcpy(sdev->cmdline, cmdline, len);
                /* Replace all commas in the command line by spaces */
                for (i = 0; i < len; i++)
                        if (sdev->cmdline[i] == ',')
index 891bdc0..b031bf4 100644 (file)
@@ -3324,17 +3324,17 @@ static int i40e_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
 
        /* Get stats from i40e_eth_stats struct */
        for (i = 0; i < I40E_NB_ETH_XSTATS; i++) {
-               snprintf(xstats_names[count].name,
-                        sizeof(xstats_names[count].name),
-                        "%s", rte_i40e_stats_strings[i].name);
+               strlcpy(xstats_names[count].name,
+                       rte_i40e_stats_strings[i].name,
+                       sizeof(xstats_names[count].name));
                count++;
        }
 
        /* Get individiual stats from i40e_hw_port struct */
        for (i = 0; i < I40E_NB_HW_PORT_XSTATS; i++) {
-               snprintf(xstats_names[count].name,
-                       sizeof(xstats_names[count].name),
-                        "%s", rte_i40e_hw_port_strings[i].name);
+               strlcpy(xstats_names[count].name,
+                       rte_i40e_hw_port_strings[i].name,
+                       sizeof(xstats_names[count].name));
                count++;
        }
 
index 22aa49c..353538f 100644 (file)
@@ -1084,8 +1084,8 @@ eth_from_pcaps_common(struct rte_vdev_device *vdev,
                struct devargs_queue *queue = &rx_queues->queue[i];
 
                pp->rx_pcap[i] = queue->pcap;
-               snprintf(rx->name, sizeof(rx->name), "%s", queue->name);
-               snprintf(rx->type, sizeof(rx->type), "%s", queue->type);
+               strlcpy(rx->name, queue->name, sizeof(rx->name));
+               strlcpy(rx->type, queue->type, sizeof(rx->type));
        }
 
        for (i = 0; i < nb_tx_queues; i++) {
@@ -1094,8 +1094,8 @@ eth_from_pcaps_common(struct rte_vdev_device *vdev,
 
                pp->tx_dumper[i] = queue->dumper;
                pp->tx_pcap[i] = queue->pcap;
-               snprintf(tx->name, sizeof(tx->name), "%s", queue->name);
-               snprintf(tx->type, sizeof(tx->type), "%s", queue->type);
+               strlcpy(tx->name, queue->name, sizeof(tx->name));
+               strlcpy(tx->type, queue->type, sizeof(tx->type));
        }
 
        return 0;
index aeb48f5..115a882 100644 (file)
@@ -497,7 +497,8 @@ static int parse_kvlist (const char *key __rte_unused, const char *value, void *
                goto out;
        }
 
-       snprintf(info->list[info->count].name, sizeof(info->list[info->count].name), "%s", name);
+       strlcpy(info->list[info->count].name, name,
+               sizeof(info->list[info->count].name));
 
        info->count++;
 
index 0cac876..36fe9f0 100644 (file)
@@ -91,7 +91,7 @@ softnic_tap_create(struct pmd_internals *p,
 
        memset(&ifr, 0, sizeof(ifr));
        ifr.ifr_flags = IFF_TAP | IFF_NO_PI; /* No packet information */
-       snprintf(ifr.ifr_name, IFNAMSIZ, "%s", name);
+       strlcpy(ifr.ifr_name, name, IFNAMSIZ);
 
        status = ioctl(fd, TUNSETIFF, (void *)&ifr);
        if (status < 0) {
index 9aae4c7..e9fda8c 100644 (file)
@@ -760,9 +760,9 @@ tap_ioctl(struct pmd_internals *pmd, unsigned long request,
         */
 apply:
        if (remote)
-               snprintf(ifr->ifr_name, IFNAMSIZ, "%s", pmd->remote_iface);
+               strlcpy(ifr->ifr_name, pmd->remote_iface, IFNAMSIZ);
        else if (mode == LOCAL_ONLY || mode == LOCAL_AND_REMOTE)
-               snprintf(ifr->ifr_name, IFNAMSIZ, "%s", pmd->name);
+               strlcpy(ifr->ifr_name, pmd->name, IFNAMSIZ);
        switch (request) {
        case SIOCSIFFLAGS:
                /* fetch current flags to leave other flags untouched */
@@ -1714,7 +1714,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
        pmd = dev->data->dev_private;
        dev->process_private = process_private;
        pmd->dev = dev;
-       snprintf(pmd->name, sizeof(pmd->name), "%s", tap_name);
+       strlcpy(pmd->name, tap_name, sizeof(pmd->name));
        pmd->type = type;
 
        pmd->ioctl_sock = socket(AF_INET, SOCK_DGRAM, 0);
@@ -1823,8 +1823,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
                                pmd->name, remote_iface);
                        goto error_remote;
                }
-               snprintf(pmd->remote_iface, RTE_ETH_NAME_MAX_LEN,
-                        "%s", remote_iface);
+               strlcpy(pmd->remote_iface, remote_iface, RTE_ETH_NAME_MAX_LEN);
 
                /* Save state of remote device */
                tap_ioctl(pmd, SIOCGIFFLAGS, &pmd->remote_initial_flags, 0, REMOTE_ONLY);
index 06916d7..e96739f 100644 (file)
@@ -145,7 +145,7 @@ static void cmd_obj_add_parsed(void *parsed_result,
                cmdline_printf(cl, "mem error\n");
                return;
        }
-       snprintf(o->name, sizeof(o->name), "%s", res->name);
+       strlcpy(o->name, res->name, sizeof(o->name));
        o->ip = res->ip;
        SLIST_INSERT_HEAD(&global_obj_list, o, next);
 
index 69eb448..5d29f9d 100644 (file)
@@ -98,7 +98,7 @@ int complete_get_elt_obj_list(cmdline_parse_token_hdr_t *tk,
                return -1;
 
        if (dstbuf)
-               snprintf(dstbuf, size, "%s", o->name);
+               strlcpy(dstbuf, o->name, size);
 
        return 0;
 }
index 8f37f5f..0d79e5a 100644 (file)
@@ -176,7 +176,7 @@ static int tap_create(char *name)
        ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
 
        if (name && *name)
-               snprintf(ifr.ifr_name, IFNAMSIZ, "%s", name);
+               strlcpy(ifr.ifr_name, name, IFNAMSIZ);
 
        ret = ioctl(fd, TUNSETIFF, (void *) &ifr);
        if (ret < 0) {
@@ -185,7 +185,7 @@ static int tap_create(char *name)
        }
 
        if (name)
-               snprintf(name, IFNAMSIZ, "%s", ifr.ifr_name);
+               strlcpy(name, ifr.ifr_name, IFNAMSIZ);
 
        return fd;
 }
index 7e5ff05..e3d0b37 100644 (file)
@@ -126,7 +126,7 @@ kni_create(const char *name, struct kni_params *params)
        rte_eth_dev_info_get(link->port_id, &dev_info);
 
        memset(&kni_conf, 0, sizeof(kni_conf));
-       snprintf(kni_conf.name, RTE_KNI_NAMESIZE, "%s", name);
+       strlcpy(kni_conf.name, name, RTE_KNI_NAMESIZE);
        kni_conf.force_bind = params->force_bind;
        kni_conf.core_id = params->thread_id;
        kni_conf.group_id = link->port_id;
index ea979bd..adae640 100644 (file)
@@ -75,7 +75,7 @@ tap_create(const char *name)
 
        memset(&ifr, 0, sizeof(ifr));
        ifr.ifr_flags = IFF_TAP | IFF_NO_PI; /* No packet information */
-       snprintf(ifr.ifr_name, IFNAMSIZ, "%s", name);
+       strlcpy(ifr.ifr_name, name, IFNAMSIZ);
 
        status = ioctl(fd, TUNSETIFF, (void *) &ifr);
        if (status < 0) {
index 9c7b315..3b448ac 100644 (file)
@@ -1384,7 +1384,7 @@ parse_ep_config(const char *q_arg)
        ep_med_edpi = EMPTY_POLL_MED_THRESHOLD;
        ep_hgh_edpi = EMPTY_POLL_MED_THRESHOLD;
 
-       snprintf(s, sizeof(s), "%s", p);
+       strlcpy(s, p, sizeof(s));
 
        num_arg = rte_strsplit(s, sizeof(s), str_fld, 3, ',');
 
index e4df6ff..bdf4947 100644 (file)
@@ -48,7 +48,7 @@ static void cmd_send_parsed(void *parsed_result,
 
        if (rte_mempool_get(message_pool, &msg) < 0)
                rte_panic("Failed to get message buffer\n");
-       snprintf((char *)msg, STR_TOKEN_SIZE, "%s", res->message);
+       strlcpy((char *)msg, res->message, STR_TOKEN_SIZE);
        if (rte_ring_enqueue(send_ring, msg) < 0) {
                printf("Failed to send message - message discarded\n");
                rte_mempool_put(message_pool, msg);
index 216e010..d40e163 100644 (file)
@@ -174,7 +174,7 @@ netmap_port_open(uint32_t idx)
 
        port->fd = rte_netmap_open("/dev/netmap", O_RDWR);
 
-       snprintf(req.nr_name, sizeof(req.nr_name), "%s", port->str);
+       strlcpy(req.nr_name, port->str, sizeof(req.nr_name));
        req.nr_version = NETMAP_API;
        req.nr_ringid = 0;
 
@@ -184,7 +184,7 @@ netmap_port_open(uint32_t idx)
                return err;
        }
 
-       snprintf(req.nr_name, sizeof(req.nr_name), "%s", port->str);
+       strlcpy(req.nr_name, port->str, sizeof(req.nr_name));
        req.nr_version = NETMAP_API;
        req.nr_ringid = 0;
 
index 0be0663..10a4379 100644 (file)
@@ -302,7 +302,7 @@ netmap_regif(struct nmreq *req, uint32_t idx, uint16_t port)
        if (req->nr_ringid != 0)
                return -EINVAL;
 
-       snprintf(nmif->ni_name, sizeof(nmif->ni_name), "%s", req->nr_name);
+       strlcpy(nmif->ni_name, req->nr_name, sizeof(nmif->ni_name));
        nmif->ni_version  = req->nr_version;
 
        /* Netmap uses ni_(r|t)x_rings + 1 */
index d6379e3..e0fe7bd 100644 (file)
@@ -191,7 +191,7 @@ us_vhost_parse_basename(const char *q_arg)
        if (strlen(q_arg) >= MAX_BASENAME_SZ)
                return -1;
        else
-               snprintf((char *)&dev_basename, MAX_BASENAME_SZ, "%s", q_arg);
+               strlcpy((char *)&dev_basename, q_arg, MAX_BASENAME_SZ);
 
        return 0;
 }
index 5e914f5..8f7b758 100644 (file)
@@ -366,7 +366,7 @@ us_vhost_parse_socket_path(const char *q_arg)
                return -1;
        }
 
-       snprintf(socket_files + nb_sockets * PATH_MAX, PATH_MAX, "%s", q_arg);
+       strlcpy(socket_files + nb_sockets * PATH_MAX, q_arg, PATH_MAX);
        nb_sockets++;
 
        return 0;
index 0c2fa3e..b1529af 100644 (file)
@@ -234,8 +234,8 @@ vhost_bdev_scsi_inquiry_command(struct vhost_block_dev *bdev,
                        desig->reserved0 = 0;
                        desig->piv = 1;
                        desig->reserved1 = 0;
-                       desig->len = snprintf((char *)desig->desig,
-                                             255, "%s", bdev->name);
+                       desig->len = strlcpy((char *)desig->desig, bdev->name,
+                                            255);
                        len += sizeof(struct scsi_desig_desc) + desig->len;
 
                        buf += sizeof(struct scsi_desig_desc) + desig->len;
@@ -281,9 +281,8 @@ vhost_bdev_scsi_inquiry_command(struct vhost_block_dev *bdev,
                        sizeof(inqdata->t10_vendor_id));
 
                /* PRODUCT IDENTIFICATION */
-               snprintf((char *)inqdata->product_id,
-                               RTE_DIM(inqdata->product_id), "%s",
-                               bdev->product_name);
+               strlcpy((char *)inqdata->product_id, bdev->product_name,
+                       RTE_DIM(inqdata->product_id));
 
                /* PRODUCT REVISION LEVEL */
                strlcpy((char *)inqdata->product_rev, "0001",
index d9042f0..53cda84 100644 (file)
@@ -69,7 +69,7 @@ cmdline_set_prompt(struct cmdline *cl, const char *prompt)
 {
        if (!cl || !prompt)
                return;
-       snprintf(cl->prompt, sizeof(cl->prompt), "%s", prompt);
+       strlcpy(cl->prompt, prompt, sizeof(cl->prompt));
 }
 
 struct cmdline *
index 9666e90..b57b30e 100644 (file)
@@ -394,8 +394,9 @@ cmdline_complete(struct cmdline *cl, const char *buf, int *state,
                                if (!strncmp(partial_tok, tmpbuf,
                                             partial_tok_len)) {
                                        if (comp_len == -1) {
-                                               snprintf(comp_buf, sizeof(comp_buf),
-                                                        "%s", tmpbuf + partial_tok_len);
+                                               strlcpy(comp_buf,
+                                                       tmpbuf + partial_tok_len,
+                                                       sizeof(comp_buf));
                                                comp_len =
                                                        strnlen(tmpbuf + partial_tok_len,
                                                                        sizeof(tmpbuf) - partial_tok_len);
index 55c7a81..182ac12 100644 (file)
@@ -340,7 +340,7 @@ cmdline_get_help_num(cmdline_parse_token_hdr_t *tk, char *dstbuf, unsigned int s
        /* if (nd.type >= (sizeof(num_help)/sizeof(const char *))) */
        /* return -1; */
 
-       ret = snprintf(dstbuf, size, "%s", num_help[nd.type]);
+       ret = strlcpy(dstbuf, num_help[nd.type], size);
        if (ret < 0)
                return -1;
        dstbuf[size-1] = '\0';
index cdc586a..2675e1e 100644 (file)
@@ -698,8 +698,8 @@ rte_cryptodev_pmd_allocate(const char *name, int socket_id)
 
                cryptodev->data = cryptodev_data;
 
-               snprintf(cryptodev->data->name, RTE_CRYPTODEV_NAME_MAX_LEN,
-                               "%s", name);
+               strlcpy(cryptodev->data->name, name,
+                       RTE_CRYPTODEV_NAME_MAX_LEN);
 
                cryptodev->data->dev_id = dev_id;
                cryptodev->data->socket_id = socket_id;
index d505983..208abfb 100644 (file)
@@ -625,7 +625,7 @@ rte_distributor_create_v1705(const char *name,
        }
 
        d = mz->addr;
-       snprintf(d->name, sizeof(d->name), "%s", name);
+       strlcpy(d->name, name, sizeof(d->name));
        d->num_workers = num_workers;
        d->alg_type = alg_type;
 
index 9566b53..cd59407 100644 (file)
@@ -386,7 +386,7 @@ rte_distributor_create_v20(const char *name,
        }
 
        d = mz->addr;
-       snprintf(d->name, sizeof(d->name), "%s", name);
+       strlcpy(d->name, name, sizeof(d->name));
        d->num_workers = num_workers;
 
        distributor_list = RTE_TAILQ_CAST(rte_distributor_tailq.head,
index 664df5b..521ad7c 100644 (file)
@@ -171,7 +171,7 @@ memzone_reserve_aligned_thread_unsafe(const char *name, size_t len,
                return NULL;
        }
 
-       snprintf(mz->name, sizeof(mz->name), "%s", name);
+       strlcpy(mz->name, name, sizeof(mz->name));
        mz->iova = rte_malloc_virt2iova(mz_addr);
        mz->addr = mz_addr;
        mz->len = requested_len == 0 ?
index babd3b3..ca2a7d3 100644 (file)
@@ -80,7 +80,7 @@ rte_eal_tailq_create(const char *name)
 
                mcfg = rte_eal_get_configuration()->mem_config;
                head = &mcfg->tailq_head[rte_tailqs_count];
-               snprintf(head->name, sizeof(head->name) - 1, "%s", name);
+               strlcpy(head->name, name, sizeof(head->name) - 1);
                TAILQ_INIT(&head->tailq_head);
                rte_tailqs_count++;
        }
index 10bdfb3..8b25c2a 100644 (file)
@@ -2068,9 +2068,9 @@ rte_eth_basic_stats_get_names(struct rte_eth_dev *dev,
        uint16_t num_q;
 
        for (idx = 0; idx < RTE_NB_STATS; idx++) {
-               snprintf(xstats_names[cnt_used_entries].name,
-                       sizeof(xstats_names[0].name),
-                       "%s", rte_stats_strings[idx].name);
+               strlcpy(xstats_names[cnt_used_entries].name,
+                       rte_stats_strings[idx].name,
+                       sizeof(xstats_names[0].name));
                cnt_used_entries++;
        }
        num_q = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
index 4fcf548..261267b 100644 (file)
@@ -381,7 +381,7 @@ rte_hash_create(const struct rte_hash_parameters *params)
                default_hash_func = (rte_hash_function)rte_hash_crc;
 #endif
        /* Setup hash context */
-       snprintf(h->name, sizeof(h->name), "%s", params->name);
+       strlcpy(h->name, params->name, sizeof(h->name));
        h->entries = params->entries;
        h->key_len = params->key_len;
        h->key_entry_size = key_entry_size;
index c9b470d..9360f79 100644 (file)
@@ -141,7 +141,7 @@ rte_fbk_hash_create(const struct rte_fbk_hash_params *params)
 #endif
 
        /* Set up hash table context. */
-       snprintf(ht->name, sizeof(ht->name), "%s", params->name);
+       strlcpy(ht->name, params->name, sizeof(ht->name));
        ht->entries = params->entries;
        ht->entries_per_bucket = params->entries_per_bucket;
        ht->used_entries = 0;
index 192f2fe..946459c 100644 (file)
@@ -234,7 +234,7 @@ rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
                goto kni_fail;
        }
 
-       snprintf(kni->name, RTE_KNI_NAMESIZE, "%s", conf->name);
+       strlcpy(kni->name, conf->name, RTE_KNI_NAMESIZE);
 
        if (ops)
                memcpy(&kni->ops, ops, sizeof(struct rte_kni_ops));
@@ -255,7 +255,7 @@ rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
 
        memcpy(dev_info.mac_addr, conf->mac_addr, ETHER_ADDR_LEN);
 
-       snprintf(dev_info.name, RTE_KNI_NAMESIZE, "%s", conf->name);
+       strlcpy(dev_info.name, conf->name, RTE_KNI_NAMESIZE);
 
        RTE_LOG(INFO, KNI, "pci: %02x:%02x:%02x \t %02x:%02x\n",
                dev_info.bus, dev_info.devid, dev_info.function,
@@ -400,7 +400,7 @@ rte_kni_release(struct rte_kni *kni)
        if (te == NULL)
                goto unlock;
 
-       snprintf(dev_info.name, sizeof(dev_info.name), "%s", kni->name);
+       strlcpy(dev_info.name, kni->name, sizeof(dev_info.name));
        if (ioctl(kni_fd, RTE_KNI_IOCTL_RELEASE, &dev_info) < 0) {
                RTE_LOG(ERR, KNI, "Fail to release kni device\n");
                goto unlock;
index d00b13d..6b7b28a 100644 (file)
@@ -205,7 +205,7 @@ rte_lpm_create_v20(const char *name, int socket_id, int max_rules,
 
        /* Save user arguments. */
        lpm->max_rules = max_rules;
-       snprintf(lpm->name, sizeof(lpm->name), "%s", name);
+       strlcpy(lpm->name, name, sizeof(lpm->name));
 
        te->data = lpm;
 
@@ -308,7 +308,7 @@ rte_lpm_create_v1604(const char *name, int socket_id,
        /* Save user arguments. */
        lpm->max_rules = config->max_rules;
        lpm->number_tbl8s = config->number_tbl8s;
-       snprintf(lpm->name, sizeof(lpm->name), "%s", name);
+       strlcpy(lpm->name, name, sizeof(lpm->name));
 
        te->data = lpm;
 
index 6212003..a918031 100644 (file)
@@ -352,7 +352,7 @@ rte_lpm6_create(const char *name, int socket_id,
        /* Save user arguments. */
        lpm->max_rules = config->max_rules;
        lpm->number_tbl8s = config->number_tbl8s;
-       snprintf(lpm->name, sizeof(lpm->name), "%s", name);
+       strlcpy(lpm->name, name, sizeof(lpm->name));
        lpm->rules_tbl = rules_tbl;
        lpm->tbl8_pool = tbl8_pool;
        lpm->tbl8_hdrs = tbl8_hdrs;
index 683b216..69bd2a6 100644 (file)
@@ -864,7 +864,7 @@ rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
        /* init the mempool structure */
        mp = mz->addr;
        memset(mp, 0, MEMPOOL_HEADER_SIZE(mp, cache_size));
-       ret = snprintf(mp->name, sizeof(mp->name), "%s", name);
+       ret = strlcpy(mp->name, name, sizeof(mp->name));
        if (ret < 0 || ret >= (int)sizeof(mp->name)) {
                rte_errno = ENAMETOOLONG;
                goto exit_unlock;
index 4f38ac5..14744b9 100644 (file)
@@ -501,15 +501,15 @@ pdump_prepare_client_request(char *device, uint16_t queue,
        req->flags = flags;
        req->op = operation;
        if ((operation & ENABLE) != 0) {
-               snprintf(req->data.en_v1.device,
-                        sizeof(req->data.en_v1.device), "%s", device);
+               strlcpy(req->data.en_v1.device, device,
+                       sizeof(req->data.en_v1.device));
                req->data.en_v1.queue = queue;
                req->data.en_v1.ring = ring;
                req->data.en_v1.mp = mp;
                req->data.en_v1.filter = filter;
        } else {
-               snprintf(req->data.dis_v1.device,
-                        sizeof(req->data.dis_v1.device), "%s", device);
+               strlcpy(req->data.dis_v1.device, device,
+                       sizeof(req->data.dis_v1.device));
                req->data.dis_v1.queue = queue;
                req->data.dis_v1.ring = NULL;
                req->data.dis_v1.mp = NULL;
index 2c047a8..f5f397d 100644 (file)
@@ -214,7 +214,7 @@ rte_pipeline_create(struct rte_pipeline_params *params)
        }
 
        /* Save input parameters */
-       snprintf(p->name, RTE_PIPELINE_MAX_NAME_SZ, "%s", params->name);
+       strlcpy(p->name, params->name, RTE_PIPELINE_MAX_NAME_SZ);
        p->socket_id = params->socket_id;
        p->offset_port_id = params->offset_port_id;
 
index 550549d..b89ecf9 100644 (file)
@@ -78,7 +78,7 @@ rte_ring_init(struct rte_ring *r, const char *name, unsigned count,
 
        /* init the ring structure */
        memset(r, 0, sizeof(*r));
-       ret = snprintf(r->name, sizeof(r->name), "%s", name);
+       ret = strlcpy(r->name, name, sizeof(r->name));
        if (ret < 0 || ret >= (int)sizeof(r->name))
                return -ENAMETOOLONG;
        r->flags = flags;