summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Certain <certain@amazon.com>2012-12-04 13:33:24 -0800
committerScott Feldman <sfeldma@cumulusnetworks.com>2013-01-07 09:59:51 -0800
commit7798b6321cd0c6281b1a119ac894ff3749e88cc1 (patch)
tree2be0e1ed9af8a9fdf156d013287c154cb081965a
parentf92c57f8ba4f1e856934ec1736be3cad62be4785 (diff)
lib: Changes to VTY string-parsing macros to remove warnings
The VTY_GET_INTEGER_RANGE macro was being used also just to check the range on a variable that wasn't used (for the "no" version of a VTY command), so I split the macro into two. Also, since the variable is unsigned, if MIN is zero, you get a warning about comparing an unsigned number against 0, giving rise to slightly convoluted logic. Note that the previous two patches were found by the -Wtype-limits and -Wunused-variables warnings. Without the changes to these macros, these warnings are triggered erroneously, making it harder to find the real problems. Signed-off-by: Scott Feldman <sfeldma@cumulusnetworks.com>
-rw-r--r--lib/vty.h46
1 files changed, 32 insertions, 14 deletions
diff --git a/lib/vty.h b/lib/vty.h
index e5158687..1798585e 100644
--- a/lib/vty.h
+++ b/lib/vty.h
@@ -149,8 +149,8 @@ struct vty
#define PRINTF_ATTRIBUTE(a,b)
#endif /* __GNUC__ */
-/* Utility macros to convert VTY argument to unsigned long or integer. */
-#define VTY_GET_LONG(NAME,V,STR) \
+/* Utility macros to convert VTY argument to unsigned long */
+#define VTY_GET_ULONG(NAME,V,STR) \
do { \
char *endptr = NULL; \
errno = 0; \
@@ -162,20 +162,38 @@ do { \
} \
} while (0)
-#define VTY_GET_INTEGER_RANGE(NAME,V,STR,MIN,MAX) \
-do { \
- unsigned long tmpl; \
- VTY_GET_LONG(NAME, tmpl, STR); \
- if ( (tmpl < (MIN)) || (tmpl > (MAX))) \
- { \
- vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \
- return CMD_WARNING; \
- } \
- (V) = tmpl; \
+/*
+ * The logic below ((TMPL) <= ((MIN) && (TMPL) != (MIN)) is
+ * done to circumvent the compiler complaining about
+ * comparing unsigned numbers against zero, if MIN is zero.
+ * NB: The compiler isn't smart enough to supress the warning
+ * if you write (MIN) != 0 && tmpl < (MIN).
+ */
+#define VTY_GET_INTEGER_RANGE_HEART(NAME,TMPL,STR,MIN,MAX) \
+do { \
+ VTY_GET_ULONG(NAME, (TMPL), STR); \
+ if ( ((TMPL) <= (MIN) && (TMPL) != (MIN)) || (TMPL) > (MAX) ) \
+ { \
+ vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE);\
+ return CMD_WARNING; \
+ } \
+} while (0)
+
+#define VTY_GET_INTEGER_RANGE(NAME,V,STR,MIN,MAX) \
+do { \
+ unsigned long tmpl; \
+ VTY_GET_INTEGER_RANGE_HEART(NAME,tmpl,STR,MIN,MAX); \
+ (V) = tmpl; \
+} while (0)
+
+#define VTY_CHECK_INTEGER_RANGE(NAME,STR,MIN,MAX) \
+do { \
+ unsigned long tmpl; \
+ VTY_GET_INTEGER_RANGE_HEART(NAME,tmpl,STR,MIN,MAX); \
} while (0)
-#define VTY_GET_INTEGER(NAME,V,STR) \
- VTY_GET_INTEGER_RANGE(NAME,V,STR,0U,UINT32_MAX)
+#define VTY_GET_INTEGER(NAME,V,STR) \
+ VTY_GET_INTEGER_RANGE(NAME,V,STR,0U,UINT32_MAX)
#define VTY_GET_IPV4_ADDRESS(NAME,V,STR) \
do { \