Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Giving empty string as value for integer variable exists the CLI shell #85

Closed
DeekshaBhandary opened this issue Mar 15, 2023 · 0 comments

Comments

@DeekshaBhandary
Copy link

Ex: consider a command that takes integer as keyword value
cli> set value

cli>set value ""              <------------Exists CLI shell

Below diff solves the problem

supervisor@deeksha_march9_spine>srv2:~/development/cligen $ git diff
diff --git a/cligen_match.c b/cligen_match.c
index 2318610..6cc4af7 100644
--- a/cligen_match.c
+++ b/cligen_match.c
@@ -155,6 +155,9 @@ match_object(cligen_handle h,
 {
   int    match = 0;
   size_t len = 0;
+  enum cv_type t;
+
+  t = co->co_vtype;
 
   if (str)
       len = strlen(str);
@@ -190,8 +193,13 @@ match_object(cligen_handle h,
       }
     break;
   case CO_VARIABLE:
-      if (str == NULL || len==0)
-          match++;
+      if (str == NULL || len==0) {
+           if ((t>= CGV_INT8) && (t<=CGV_DEC64)) {
+               *reason = cligen_reason("'%s' is not a number", str);
+           } else {
+               match++;
+           }
+      }
       else
           if ((match = match_variable(h, co, str, reason)) < 0)
               return -1;
supervisor@deeksha_march9_spine>srv2:~/development/cligen $
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants