summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSteven Luong <sluong@cisco.com>2019-07-24 11:16:46 -0700
committerDamjan Marion <dmarion@me.com>2019-07-25 09:00:41 +0000
commit0dbaa59e075f9ac44b0bd23ed2c9adbd85215e8f (patch)
treef9988bfc424f381179ea35a9700c0bf54a347ce2 /src
parentc94afaade0a8fec724d051a202591f5b37dd0f49 (diff)
memif: Fix uninitialized variable as reported by coverity
When mode == ip, the variable next_index is not initialized. Although insde the while loop, ni will be fixed to contain next[0], it is easier to initialize it. Type: fix Change-Id: I6653a958bbc5105e7266bf89e3c8569ff00f0199 Signed-off-by: Steven Luong <sluong@cisco.com>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/memif/node.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/plugins/memif/node.c b/src/plugins/memif/node.c
index a4b8245b520..154d2444957 100644
--- a/src/plugins/memif/node.c
+++ b/src/plugins/memif/node.c
@@ -185,7 +185,8 @@ memif_device_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
u16 nexts[MEMIF_RX_VECTOR_SZ], *next = nexts;
u32 _to_next_bufs[MEMIF_RX_VECTOR_SZ], *to_next_bufs = _to_next_bufs, *bi;
u32 n_rx_packets = 0, n_rx_bytes = 0;
- u32 n_left, n_left_to_next, next_index;
+ u32 n_left, n_left_to_next;
+ u32 next_index = VNET_DEVICE_INPUT_NEXT_ETHERNET_INPUT;
vlib_buffer_t *b0, *b1, *b2, *b3;
u32 thread_index = vm->thread_index;
memif_per_thread_data_t *ptd = vec_elt_at_index (mm->per_thread_data,
='n176' href='#n176'>176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
/*
 * Copyright (c) 2015 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <vppinfra/ptclosure.h>
#include <vppinfra/hash.h>

typedef struct
{
  uword *index_by_name;
  u8 *items;
} test_main_t;

test_main_t test_main;

static char *items[] = {
  "d",
  "a",
  "b",
  "c",
};

char *constraints[] = {
  "a,b",
  "b,c",
  "d,b",
  //    "c,a", /* no partial order possible */
};

u32
vl (void *p)
{
  return vec_len (p);
}

static void
dump_closure (test_main_t * tm, char *s, u8 ** orig)
{
  int i, j;

  fformat (stdout, "--------- %s --------------\n", s);
  for (i = 0; i < vec_len (orig); i++)
    {
      for (j = 0; j < vec_len (orig); j++)
	if (orig[i][j])
	  {
	    fformat (stdout, "%s <before> %s\n", items[i], items[j]);
	  }
    }
}

int
comma_split (u8 * s, u8 ** a, u8 ** b)
{
  *a = s;

  while (*s && *s != ',')
    s++;

  if (*s == ',')
    *s = 0;
  else
    return 1;

  *b = (u8 *) (s + 1);
  return 0;
}

int
test_ptclosure_main (unformat_input_t * input)
{
  test_main_t *tm = &test_main;
  u8 *item_name;
  int i, j;
  u8 **orig;
  u8 **closure;
  u8 *a_name, *b_name;
  int a_index, b_index;
  uword *p;
  u8 *this_constraint;
  int n;
  u32 *result = 0;

  tm->index_by_name = hash_create_string (0, sizeof (uword));

  n = ARRAY_LEN (items);

  for (i = 0; i < n; i++)
    {
      item_name = (u8 *) items[i];
      hash_set_mem (tm->index_by_name, item_name, i);
    }

  orig = clib_ptclosure_alloc (n);

  for (i = 0; i < ARRAY_LEN (constraints); i++)
    {
      this_constraint = format (0, "%s%c", constraints[i], 0);

      if (comma_split (this_constraint, &a_name, &b_name))
	{
	  clib_warning ("couldn't split '%s'", constraints[i]);
	  return 1;
	}

      p = hash_get_mem (tm->index_by_name, a_name);
      if (p == 0)
	{
	  clib_warning ("couldn't find '%s'", a_name);
	  return 1;
	}
      a_index = p[0];

      p = hash_get_mem (tm->index_by_name, b_name);
      if (p == 0)
	{
	  clib_warning ("couldn't find '%s'", b_name);
	  return 1;
	}
      b_index = p[0];

      orig[a_index][b_index] = 1;
      vec_free (this_constraint);
    }

  dump_closure (tm, "original relation", orig);

  closure = clib_ptclosure (orig);

  dump_closure (tm, "closure", closure);

  /*
   * Output partial order
   */

again:
  for (i = 0; i < n; i++)
    {
      for (j = 0; j < n; j++)
	{
	  if (closure[i][j])
	    goto item_constrained;
	}
      /* Item i can be output */
      vec_add1 (result, i);
      {
	int k;
	for (k = 0; k < n; k++)
	  closure[k][i] = 0;
	/* "Magic" a before a, to keep from ever outputting it again */
	closure[i][i] = 1;
	goto again;
      }
    item_constrained:
      ;
    }

  if (vec_len (result) != n)
    {
      clib_warning ("no partial order exists");
      exit (1);
    }

  fformat (stdout, "Partial order:\n");

  for (i = vec_len (result) - 1; i >= 0; i--)
    {
      fformat (stdout, "%s\n", items[result[i]]);
    }

  vec_free (result);
  clib_ptclosure_free (orig);
  clib_ptclosure_free (closure);

  return 0;
}

#ifdef CLIB_UNIX
int
main (int argc, char *argv[])
{
  unformat_input_t i;
  int ret;

  clib_mem_init (0, 3ULL << 30);

  unformat_init_command_line (&i, argv);
  ret = test_ptclosure_main (&i);
  unformat_free (&i);

  return ret;
}
#endif /* CLIB_UNIX */

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */