MTRIE Optimisations 2
[vpp.git] / src / vpp / api / api_main.c
index 7913bc0..d48e4ef 100644 (file)
@@ -47,6 +47,8 @@ api_main_init (vlib_main_t * vm)
 
   vam->vlib_main = vm;
   vam->my_client_index = (u32) ~ 0;
+  /* Ensure that vam->inbuf is never NULL */
+  vec_validate (vam->inbuf, 0);
   init_error_string_table (vam);
   rv = vat_plugin_init (vam);
   if (rv)
@@ -82,17 +84,20 @@ api_command_fn (vlib_main_t * vm,
 
   vam->vl_input_queue = am->shmem_hdr->vl_input_queue;
 
-  vec_reset_length (vam->inbuf);
+  /* vec_validated in the init routine */
+  _vec_len (vam->inbuf) = 0;
+
   vam->input = &_input;
 
   while (((c = unformat_get_input (input)) != '\n') &&
         (c != UNFORMAT_END_OF_INPUT))
     vec_add1 (vam->inbuf, c);
 
-  /* Add 1 octet's worth of extra space in case there are no args... */
+  /* Null-terminate the command */
   vec_add1 (vam->inbuf, 0);
 
-  /*$$$$ reinstall macro evaluator */
+  /* In case no args given */
+  vec_add1 (vam->inbuf, 0);
 
   /* Split input into cmd + args */
   this_cmd = cmdp = vam->inbuf;
@@ -113,7 +118,7 @@ api_command_fn (vlib_main_t * vm,
   /* Advance past the command */
   while (argsp < (this_cmd + vec_len (this_cmd)))
     {
-      if (*argsp != ' ' && *argsp != '\t' && *argsp != '\n' && argsp != 0)
+      if (*argsp != ' ' && *argsp != '\t' && *argsp != '\n' && *argsp != 0)
        {
          argsp++;
        }
@@ -123,15 +128,19 @@ api_command_fn (vlib_main_t * vm,
   /* NULL terminate the command */
   *argsp++ = 0;
 
-  while (argsp < (this_cmd + vec_len (this_cmd)))
-    {
-      if (*argsp == ' ' || *argsp == '\t' || *argsp == '\n')
-       {
-         argsp++;
-       }
-      else
-       break;
-    }
+  /* No arguments? Ensure that argsp points to a proper (empty) string */
+  if (argsp == (this_cmd + vec_len (this_cmd) - 1))
+    argsp[0] = 0;
+  else
+    while (argsp < (this_cmd + vec_len (this_cmd)))
+      {
+       if (*argsp == ' ' || *argsp == '\t' || *argsp == '\n')
+         {
+           argsp++;
+         }
+       else
+         break;
+      }
 
   /* Blank input line? */
   if (*cmdp == 0)