[Git][NTPsec/ntpsec][master] Added try/except guard to --width option integer conversion

Eric S. Raymond gitlab at mg.gitlab.com
Mon Mar 20 21:08:55 UTC 2017


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
914fde0c by Ian Bruene at 2017-03-20T13:46:31-05:00
Added try/except guard to --width option integer conversion

Previously the option handling in the if __name__ == '__main__': block was
 inconsistent; the -D option wrote a message to stderr and did
 raise SystemExit if the option could not be converted to an int. But the
 -W option did not have this guard, despite also requiring an int and having
 no obvious reason why it shouldn't be guarded.

- - - - -


1 changed file:

- ntpclients/ntpq


Changes:

=====================================
ntpclients/ntpq
=====================================
--- a/ntpclients/ntpq
+++ b/ntpclients/ntpq
@@ -1623,7 +1623,12 @@ if __name__ == '__main__':
         elif switch in ("-w", "--wide"):
             interpreter.wideremote = True
         elif switch in ("-W", "--width"):
-            interpreter.termwidth = int(val)
+            try:
+                interpreter.termwidth = int(val)
+            except ValueError as e:
+                sys.stderr.write("'%s' is not a recognizable number\n" % val)
+                sys.stderr.write(usage)
+                raise SystemExit(1)
 
     if interpreter.interactive and len(interpreter.ccmds) > 0:
         interpreter.warn("%s: invalid option combination.\n" % progname)



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/914fde0c580418ceeefdfd277369a4d59b91c9c7
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170320/d81bf1c4/attachment.html>


More information about the vc mailing list