Browse Source

2004-10-13 Paul Jakma <paul@dishone.st>

	* (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.
paul 17 years ago
parent
commit
42d498658d
6 changed files with 41 additions and 25 deletions
  1. 13 0
      lib/ChangeLog
  2. 1 1
      lib/command.c
  3. 1 1
      lib/command.h
  4. 4 4
      lib/sockunion.c
  5. 1 1
      lib/sockunion.h
  6. 21 18
      lib/vty.h

+ 13 - 0
lib/ChangeLog

@@ -1,3 +1,16 @@
+2004-10-13 Paul Jakma <paul@dishone.st>
+
+	* (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.
+
 2004-10-11 Hasso Tepper <hasso at quagga.net>
 
 	* command.h: Sync DEFUNSH with other macros.

+ 1 - 1
lib/command.c

@@ -78,7 +78,7 @@ struct cmd_node config_node =
 /* Utility function to concatenate argv argument into a single string
    with inserting ' ' character between each argument.  */
 char *
-argv_concat (char **argv, int argc, int shift)
+argv_concat (const char **argv, int argc, int shift)
 {
   int i;
   int len;

+ 1 - 1
lib/command.h

@@ -286,7 +286,7 @@ void install_default (enum node_type);
 void install_element (enum node_type, struct cmd_element *);
 void sort_node ();
 
-char *argv_concat (char **, int, int);
+char *argv_concat (const char **, int, int);
 vector cmd_make_strvec (const char *);
 void cmd_free_strvec (vector);
 vector cmd_describe_command ();

+ 4 - 4
lib/sockunion.c

@@ -175,7 +175,7 @@ sockunion2str (union sockunion *su, char *buf, size_t len)
 }
 
 union sockunion *
-sockunion_str2su (char *str)
+sockunion_str2su (const char *str)
 {
   int ret;
   union sockunion *su;
@@ -211,7 +211,7 @@ sockunion_str2su (char *str)
 char *
 sockunion_su2str (union sockunion *su)
 {
-  char str[INET6_ADDRSTRLEN];
+  char str[SU_ADDRSTRLEN];
 
   switch (su->sa.sa_family)
     {
@@ -314,7 +314,7 @@ sockunion_log (union sockunion *su)
       snprintf (buf, SU_ADDRSTRLEN, "af_unknown %d ", su->sa.sa_family);
       break;
     }
-  return buf;
+  return (strdup (buf));
 }
 
 /* sockunion_connect returns
@@ -676,7 +676,7 @@ sockunion_print (union sockunion *su)
 #ifdef HAVE_IPV6
     case AF_INET6:
       {
-	char buf [64];
+	char buf [SU_ADDRSTRLEN];
 
 	printf ("%s\n", inet_ntop (AF_INET6, &(su->sin6.sin6_addr),
 				 buf, sizeof (buf)));

+ 1 - 1
lib/sockunion.h

@@ -93,7 +93,7 @@ int sockunion_cmp (union sockunion *, union sockunion *);
 int sockunion_same (union sockunion *, union sockunion *);
 
 char *sockunion_su2str (union sockunion *su);
-union sockunion *sockunion_str2su (char *str);
+union sockunion *sockunion_str2su (const char *str);
 struct in_addr sockunion_get_in_addr (union sockunion *su);
 int sockunion_accept (int sock, union sockunion *);
 int sockunion_stream_socket (union sockunion *);

+ 21 - 18
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[];