From 42d498658d85e36a7e5910955e7425b1fa2afa69 Mon Sep 17 00:00:00 2001 From: paul Date: Wed, 13 Oct 2004 05:22:18 +0000 Subject: 2004-10-13 Paul Jakma * (global) more const'ification. * sockunion.c: (sockunion_su2str) buffer should be sized SU_ADDRSTRLEN. (sockunion_log) do not return stack variables, strdup buf before return. * vty.h: Fix up the VTY_GET_INTEGER macros. Testing caller supplied values against ULONG_MAX is daft, when caller probably has passed a type that can not hold ULONG_MAX. use a temporary long instead. Add VTY_GET_LONG, make VTY_GET_INTEGER_RANGE use it, make VTY_GET_INTEGER a define for VTY_GET_INTEGER_RANGE. --- lib/vty.h | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'lib/vty.h') diff --git a/lib/vty.h b/lib/vty.h index ffaad357..c5c8c3b0 100644 --- a/lib/vty.h +++ b/lib/vty.h @@ -158,30 +158,33 @@ struct vty #define PRINTF_ATTRIBUTE(a,b) #endif /* __GNUC__ */ -/* Utility macro to convert VTY argument to unsigned integer. */ -#define VTY_GET_INTEGER(NAME,V,STR) \ -{ \ - char *endptr = NULL; \ - (V) = strtoul ((STR), &endptr, 10); \ - if ((V) == ULONG_MAX || *endptr != '\0') \ - { \ +/* Utility macros to convert VTY argument to unsigned long or integer. */ +#define VTY_GET_LONG(NAME,V,STR) \ +{ \ + char *endptr = NULL; \ + (V) = strtoul ((STR), &endptr, 10); \ + if (*endptr != '\0' || (V) == ULONG_MAX) \ + { \ vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \ - return CMD_WARNING; \ - } \ + return CMD_WARNING; \ + } \ } -#define VTY_GET_INTEGER_RANGE(NAME,V,STR,MIN,MAX) \ -{ \ - char *endptr = NULL; \ - (V) = strtoul ((STR), &endptr, 10); \ - if ((V) == ULONG_MAX || *endptr != '\0' \ - || (V) < (MIN) || (V) > (MAX)) \ - { \ +#define VTY_GET_INTEGER_RANGE(NAME,V,STR,MIN,MAX) \ +{ \ + 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; \ - } \ + return CMD_WARNING; \ + } \ + (V) = tmpl; \ } +#define VTY_GET_INTEGER(NAME,V,STR) \ + VTY_GET_INTEGER_RANGE(NAME,V,STR,0U,UINT32_MAX) + /* Exported variables */ extern char integrate_default[]; -- cgit v1.2.1