]> git.puffer.fish Git - matthieu/frr.git/commitdiff
2004-10-13 Paul Jakma <paul@dishone.st>
authorpaul <paul>
Wed, 13 Oct 2004 05:22:18 +0000 (05:22 +0000)
committerpaul <paul>
Wed, 13 Oct 2004 05:22:18 +0000 (05:22 +0000)
* (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/ChangeLog
lib/command.c
lib/command.h
lib/sockunion.c
lib/sockunion.h
lib/vty.h

index 9a01f63682e8ce1fb5560254d2c949926f980f8b..1e6f51ca49f0bc095b0bc22062060a487573bf95 100644 (file)
@@ -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.
index 168fe563f0071de02e87f79952d968ca05f11697..0e61e0d8d1ae414d0767e10201b5bf131e8953c8 100644 (file)
@@ -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;
index a8387346e939684192c37a80cf6ae28bd1aec527..8faf534d0ac4b5b9aad9c491221829e54c662206 100644 (file)
@@ -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 ();
index eb29ced2c537b8ae6bf318c0ef2b189599f05cdb..78e02f26e80c5500a9003b74bcc9757c9baba3aa 100644 (file)
@@ -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)));
index 92e536c121c87e7ee84b3abc78ac46c00921c154..738df06c5038cad402268cc754ce9ea1ac2c4d98 100644 (file)
@@ -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 *);
index ffaad35700f5e06b7cd8efd9336d21c64f1f11ff..c5c8c3b0b0df1bf4c825c405c147a5f10655361e 100644 (file)
--- 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[];