>>>>> "TA" == Thomas Anders <[EMAIL PROTECTED]> writes:

TA> -coders subject was "Re: rfv: remove asserts with undefined string
TA> comparisons". I'm attaching it here again for convenience.

Ugh.  -1.

How about a counter proposal, since I don't think that patch is
necessarily any purer (it is still comparing strings)...

Change those lines to debugging statements and assert that 1 != 0
instead to get it to stop.

(Boy am I tempted to do a number of things to the error support in a
number of places...  This patch doesn't do what I think needs to be
done, but yet is probably safer given the time frame involved)

I haven't tested it under all conditions (IE, when asserting is turned
on) but it works in the default state.


Index: snmplib/data_list.c
===================================================================
--- snmplib/data_list.c (revision 16583)
+++ snmplib/data_list.c (working copy)
@@ -105,7 +105,7 @@
 
     DEBUGMSGTL(("data_list","adding key '%s'\n", node->name));
     if (0 == strcmp(node->name, (*head)->name)) {
-        netsnmp_assert("list key" == "is unique"); /* always fail */
+        netsnmp_error("list key == is unique"); /* always fail */
         snmp_log(LOG_WARNING,
                  "WARNING: adding duplicate key '%s' to data list\n",
                  node->name);
@@ -114,7 +114,7 @@
     for (ptr = *head; ptr->next != NULL; ptr = ptr->next) {
         netsnmp_assert(NULL != ptr->name);
         if (0 == strcmp(node->name, ptr->name)) {
-            netsnmp_assert("list key" == "is unique"); /* always fail */
+            netsnmp_error("list key == is unique"); /* always fail */
             snmp_log(LOG_WARNING,
                      "WARNING: adding duplicate key '%s' to data list\n",
                      node->name);
Index: snmplib/snmp_client.c
===================================================================
--- snmplib/snmp_client.c       (revision 16583)
+++ snmplib/snmp_client.c       (working copy)
@@ -877,7 +877,7 @@
 
     case ASN_IPADDRESS: /* snmp_build_var_op treats IPADDR like a string */
         if (4 != vars->val_len) {
-            netsnmp_assert("ipaddress length == 4");
+            netsnmp_error("ipaddress length == 4");
         }
         /** FALL THROUGH */
     case ASN_PRIV_IMPLIED_OCTET_STR:
Index: snmplib/callback.c
===================================================================
--- snmplib/callback.c  (revision 16583)
+++ snmplib/callback.c  (working copy)
@@ -109,7 +109,7 @@
 {
 #ifdef NETSNMP_PARANOID_LEVEL_HIGH
     if (major >= MAX_CALLBACK_IDS || minor >= MAX_CALLBACK_SUBIDS) {
-        netsnmp_assert("bad callback id");
+        netsnmp_error("bad callback id");
         return 1;
     }
 #endif
@@ -139,7 +139,7 @@
 {
 #ifdef NETSNMP_PARANOID_LEVEL_HIGH
     if (major >= MAX_CALLBACK_IDS || minor >= MAX_CALLBACK_SUBIDS) {
-        netsnmp_assert("bad callback id");
+        netsnmp_error("bad callback id");
         return;
     }
 #endif
Index: include/net-snmp/library/snmp_assert.h
===================================================================
--- include/net-snmp/library/snmp_assert.h      (revision 16583)
+++ include/net-snmp/library/snmp_assert.h      (working copy)
@@ -28,7 +28,9 @@
  */
 #ifdef NETSNMP_USE_ASSERT
 /*   void netsnmp_assert( int );*/
-#   define netsnmp_assert(x)  assert( x )
+#   define netsnmp_assert(x)           assert( x )
+#   define netsnmp_assert_error(x,y)   assert(x)
+#   define netsnmp_error(y)            assert(1 == 0)
 #else
 /*
  *  if asserts weren't requested, just log, unless NETSNMP_NO_DEBUGGING 
specified
@@ -43,6 +45,18 @@
                              __STRING(x),__FILE__,__LINE__, \
                              NETSNMP_FUNCTION); \
               }while(0)
+#         define netsnmp_assert_error(x,y)  do { \
+                 if ( x ) \
+                    ; \
+                 else \
+                    snmp_log(LOG_ERR, "netsnmp_assert %s failed: \"%s\" at 
%s:%d %s()\n", \
+                             __STRING(x), y, __FILE__,__LINE__,          \
+                             NETSNMP_FUNCTION); \
+              }while(0)
+#         define netsnmp_error(y) \
+                    snmp_log(LOG_ERR, "netsnmp_error \"%s\" at %s:%d %s()\n", \
+                             y, __FILE__,__LINE__,          \
+                             NETSNMP_FUNCTION);
 #      else
 #         define netsnmp_assert(x)  do { \
                  if( x )\
@@ -51,9 +65,23 @@
                     snmp_log(LOG_ERR,"netsnmp_assert %s failed %s:%d\n", \
                              __STRING(x),__FILE__,__LINE__); \
               }while(0)
+#         define netsnmp_assert_error(x,y)  do { \
+                 if( x )\
+                    ; \
+                 else \
+                    snmp_log(LOG_ERR, \
+                             "netsnmp_assert %s failed: \"%s\" at %s:%d\n", \
+                             __STRING(x), y,__FILE__,__LINE__); \
+              }while(0)
+#         define netsnmp_error(y) \
+                    snmp_log(LOG_ERR, \
+                             "netsnmp_error \"%s\" at %s:%d\n", \
+                             y,__FILE__,__LINE__);
 #      endif
 #   else /* NO DEBUGGING */
 #      define netsnmp_assert(x)
+#      define netsnmp_assert_error(x, y)
+#      define netsnmp_error(y)
 #   endif /* NO DEBUGGING */
 #endif /* not NETSNMP_USE_ASSERT */
 
Index: agent/mibgroup/if-mib/ifTable/ifTable.c
===================================================================
--- agent/mibgroup/if-mib/ifTable/ifTable.c     (revision 16583)
+++ agent/mibgroup/if-mib/ifTable/ifTable.c     (working copy)
@@ -2339,7 +2339,7 @@
         snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
                                  (u_char *) &val, sizeof(val));
     } else
-        netsnmp_assert("bad mode in RO handler");
+        netsnmp_error("bad mode in RO handler");
     
     if (handler->next && handler->next->access_method)
         return netsnmp_call_next_handler(handler, reginfo, reqinfo,
Index: agent/mibgroup/ip-mib/data_access/ipaddress_common.c
===================================================================
--- agent/mibgroup/ip-mib/data_access/ipaddress_common.c        (revision 16583)
+++ agent/mibgroup/ip-mib/data_access/ipaddress_common.c        (working copy)
@@ -239,7 +239,7 @@
     }
     else {
         snmp_log(LOG_ERR,"netsnmp_access_ipaddress_entry_set with no mode\n");
-        netsnmp_assert("ipaddress_entry_set" == "unknown mode"); 
+        netsnmp_error("ipaddress_entry_set == unknown mode"); 
         rc = -1;
     }
     
Index: agent/mibgroup/ip-forward-mib/inetCidrRouteTable/inetCidrRouteTable.c
===================================================================
--- agent/mibgroup/ip-forward-mib/inetCidrRouteTable/inetCidrRouteTable.c       
(revision 16583)
+++ agent/mibgroup/ip-forward-mib/inetCidrRouteTable/inetCidrRouteTable.c       
(working copy)
@@ -2663,7 +2663,7 @@
         snmp_set_var_typed_value(requests->requestvb, ASN_UNSIGNED,
                                  (u_char *) &val, sizeof(val));
     } else
-        netsnmp_assert("bad mode in RO handler");
+        netsnmp_error("bad mode in RO handler");
     
     if (handler->next && handler->next->access_method)
         return netsnmp_call_next_handler(handler, reginfo, reqinfo,
Index: agent/mibgroup/ip-forward-mib/data_access/route_common.c
===================================================================
--- agent/mibgroup/ip-forward-mib/data_access/route_common.c    (revision 16583)
+++ agent/mibgroup/ip-forward-mib/data_access/route_common.c    (working copy)
@@ -173,7 +173,7 @@
     }
     else {
         snmp_log(LOG_ERR,"netsnmp_access_route_entry_set with no mode\n");
-        netsnmp_assert("route_entry_set" == "unknown mode"); 
+        netsnmp_error("route_entry_set == unknown mode"); 
         rc = -1;
     }
     
Index: agent/mibgroup/mibII/ip.c
===================================================================
--- agent/mibgroup/mibII/ip.c   (revision 16583)
+++ agent/mibgroup/mibII/ip.c   (working copy)
@@ -250,7 +250,7 @@
     ip_load(NULL, NULL);
 #elif !defined(hpux11)
     if (!netsnmp_cache_is_valid(reqinfo, reginfo->handlerName)) {
-        netsnmp_assert("cache" == "valid"); /* always false */
+        netsnmp_error("cache == valid"); /* always false */
         ip_load( NULL, NULL ); /* XXX - check for failure */
     }
 #endif
Index: agent/mibgroup/mibII/udp.c
===================================================================
--- agent/mibgroup/mibII/udp.c  (revision 16583)
+++ agent/mibgroup/mibII/udp.c  (working copy)
@@ -197,7 +197,7 @@
     udp_load(NULL, NULL);
 #elif !defined(hpux11)
     if (!netsnmp_cache_is_valid(reqinfo, reginfo->handlerName)) {
-        netsnmp_assert("cache" == "valid"); /* always false */
+        netsnmp_error("cache == valid"); /* always false */
         udp_load( NULL, NULL );        /* XXX - check for failure */
     }
 #endif
Index: agent/mibgroup/mibII/tcp.c
===================================================================
--- agent/mibgroup/mibII/tcp.c  (revision 16583)
+++ agent/mibgroup/mibII/tcp.c  (working copy)
@@ -215,7 +215,7 @@
     tcp_load(NULL, NULL);
 #elif !defined(hpux11)
     if (!netsnmp_cache_is_valid(reqinfo, reginfo->handlerName)) {
-        netsnmp_assert("cache" == "valid"); /* always false */
+        netsnmp_error("cache == valid"); /* always false */
         tcp_load( NULL, NULL );        /* XXX - check for failure */
     }
 #endif
Index: agent/mibgroup/mibII/icmp.c
===================================================================
--- agent/mibgroup/mibII/icmp.c (revision 16583)
+++ agent/mibgroup/mibII/icmp.c (working copy)
@@ -297,7 +297,7 @@
     icmp_load(NULL, NULL);
 #elif !defined(hpux11)
     if (!netsnmp_cache_is_valid(reqinfo, reginfo->handlerName)) {
-        netsnmp_assert("cache" == "valid"); /* always false */
+        netsnmp_error("cache == valid"); /* always false */
         icmp_load( NULL, NULL );       /* XXX - check for failure */
     }
 #endif
Index: agent/helpers/baby_steps.c
===================================================================
--- agent/helpers/baby_steps.c  (revision 16583)
+++ agent/helpers/baby_steps.c  (working copy)
@@ -509,7 +509,7 @@
         case MODE_BSTEP_UNDO_COMMIT:
             return BABY_STEP_UNDO_COMMIT;
         default:
-            netsnmp_assert("unknown flag");
+            netsnmp_error("unknown flag");
             break;
     }
     return 0;
Index: agent/agent_registry.c
===================================================================
--- agent/agent_registry.c      (revision 16583)
+++ agent/agent_registry.c      (working copy)
@@ -530,7 +530,7 @@
        
            if (next && (next->namelen  == new_sub->namelen) &&
                (next->priority == new_sub->priority)) {
-                netsnmp_assert("registration" != "duplicate");
+                netsnmp_error("registration != duplicate");
                return MIB_DUPLICATE_REGISTRATION;
            }
 
@@ -624,7 +624,7 @@
         snmp_log(LOG_WARNING,"context passed during registration does not "
                  "equal the reginfo contextName! ('%s' != '%s')\n",
                  context, reginfo->contextName);
-        netsnmp_assert("register context" == "reginfo->contextName");
+        netsnmp_error("register context == reginfo->contextName");
     }
 
     /*  Create the new subtree node being registered.  */
Index: agent/snmp_agent.c
===================================================================
--- agent/snmp_agent.c  (revision 16583)
+++ agent/snmp_agent.c  (working copy)
@@ -1166,7 +1166,7 @@
         DEBUGMSGTL(("snmp_agent",
                     "init_master_agent; not master agent\n"));
 
-        netsnmp_assert("agent role !master && !sub_agent");
+        netsnmp_error("agent role !master && !sub_agent");
         
         return 0;               /*  No error if ! MASTER_AGENT  */
     }

-- 
Wes Hardaker
Sparta, Inc.

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to