From: Tyler Retzlaff <roret...@linux.microsoft.com>

MSVC does not support VLAs, replace VLAs with standard C arrays
or alloca(). alloca() is available for all toolchain/platform
combinations officially supported by DPDK.

Signed-off-by: Tyler Retzlaff <roret...@linux.microsoft.com>
Acked-by: Chengwen Feng <fengcheng...@huawei.com>
---
 app/test-pmd/cmdline.c      |  2 +-
 app/test-pmd/cmdline_flow.c | 15 ++++++++++-----
 app/test-pmd/config.c       | 16 +++++++++-------
 3 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 7e0666e9f6..2897e44c34 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -13274,7 +13274,7 @@ cmd_set_port_ptypes_parsed(
                return;
        }
 
-       uint32_t ptypes[ret];
+       uint32_t *ptypes = alloca(sizeof(uint32_t) * ret);
 
        ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
        if (ret < 0) {
diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index 9e4fc2d95d..e1720e54d7 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -11707,8 +11707,7 @@ parse_hex(struct context *ctx, const struct token 
*token,
        char tmp[16]; /* Ought to be enough. */
        int ret;
        unsigned int hexlen = len;
-       unsigned int length = 256;
-       uint8_t hex_tmp[length];
+       uint8_t hex_tmp[256];
 
        /* Arguments are expected. */
        if (!arg_data)
@@ -11735,7 +11734,7 @@ parse_hex(struct context *ctx, const struct token 
*token,
                str += 2;
                hexlen -= 2;
        }
-       if (hexlen > length)
+       if (hexlen > RTE_DIM(hex_tmp))
                goto error;
        ret = parse_hex_string(str, hex_tmp, &hexlen);
        if (ret < 0)
@@ -11868,10 +11867,13 @@ parse_ipv4_addr(struct context *ctx, const struct 
token *token,
                void *buf, unsigned int size)
 {
        const struct arg *arg = pop_args(ctx);
-       char str2[len + 1];
+       char str2[INET_ADDRSTRLEN];
        struct in_addr tmp;
        int ret;
 
+       /* Length is longer than the max length an IPv4 address can have. */
+       if (len >= INET_ADDRSTRLEN)
+               return -1;
        /* Argument is expected. */
        if (!arg)
                return -1;
@@ -11914,11 +11916,14 @@ parse_ipv6_addr(struct context *ctx, const struct 
token *token,
                void *buf, unsigned int size)
 {
        const struct arg *arg = pop_args(ctx);
-       char str2[len + 1];
+       char str2[INET6_ADDRSTRLEN];
        struct rte_ipv6_addr tmp;
        int ret;
 
        (void)token;
+       /* Length is longer than the max length an IPv6 address can have. */
+       if (len >= INET6_ADDRSTRLEN)
+               return -1;
        /* Argument is expected. */
        if (!arg)
                return -1;
diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index 4e7fb69183..b19df95321 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -1802,7 +1802,8 @@ port_flow_configure(portid_t port_id,
 {
        struct rte_port *port;
        struct rte_flow_error error;
-       const struct rte_flow_queue_attr *attr_list[nb_queue];
+       const struct rte_flow_queue_attr **attr_list =
+           alloca(sizeof(struct rte_flow_queue_attr *) * nb_queue);
        int std_queue;
 
        if (port_id_is_invalid(port_id, ENABLED_WARN) ||
@@ -2616,10 +2617,10 @@ port_flow_template_table_create(portid_t port_id, 
uint32_t id,
        int ret;
        uint32_t i;
        struct rte_flow_error error;
-       struct rte_flow_pattern_template
-                       *flow_pattern_templates[nb_pattern_templates];
-       struct rte_flow_actions_template
-                       *flow_actions_templates[nb_actions_templates];
+       struct rte_flow_pattern_template **flow_pattern_templates =
+           alloca(sizeof(struct rte_flow_pattern_template *) * 
nb_pattern_templates);
+       struct rte_flow_actions_template **flow_actions_templates =
+           alloca(sizeof(struct rte_flow_actions_template *) * 
nb_actions_templates);
 
        if (port_id_is_invalid(port_id, ENABLED_WARN) ||
            port_id == (portid_t)RTE_PORT_ALL)
@@ -5551,7 +5552,7 @@ parse_port_list(const char *list, unsigned int *values, 
unsigned int maxsize)
        char *end = NULL;
        int min, max;
        int value, i;
-       unsigned int marked[maxsize];
+       unsigned int *marked = alloca(sizeof(unsigned int) * maxsize);
 
        if (list == NULL || values == NULL)
                return 0;
@@ -7292,7 +7293,8 @@ show_macs(portid_t port_id)
        if (eth_dev_info_get_print_err(port_id, &dev_info))
                return;
 
-       struct rte_ether_addr addr[dev_info.max_mac_addrs];
+       struct rte_ether_addr *addr =
+           alloca(sizeof(struct rte_ether_addr) * dev_info.max_mac_addrs);
        rc = rte_eth_macaddrs_get(port_id, addr, dev_info.max_mac_addrs);
        if (rc < 0)
                return;
-- 
2.47.2.vfs.0.1

Reply via email to