]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/oidm.c
address ITS#4332; might remove dynamicObject counting
[openldap] / servers / slapd / oidm.c
index 99df108cdaaf0585db00cb1999dd48cffa714325..0bc6f53102d32896b7c1c0101d8d258b1fa0a7aa 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2005 The OpenLDAP Foundation.
+ * Copyright 1998-2006 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -119,9 +119,9 @@ usage:      fprintf( stderr, "\tObjectIdentifier <name> <oid>\n");
                return 1;
        }
 
-       om = (OidMacro *) SLAP_MALLOC( sizeof(OidMacro) );
+       om = (OidMacro *) SLAP_CALLOC( sizeof(OidMacro), 1 );
        if( om == NULL ) {
-               Debug( LDAP_DEBUG_ANY, "parse_oidm: SLAP_MALLOC failed", 0, 0, 0 );
+               Debug( LDAP_DEBUG_ANY, "parse_oidm: SLAP_CALLOC failed", 0, 0, 0 );
                return 1;
        }
 
@@ -156,7 +156,7 @@ void oidm_unparse( BerVarray *res, OidMacro *start, OidMacro *end, int sys )
 {
        OidMacro *om;
        int i, j, num;
-       struct berval bv, *bva = NULL, idx;
+       struct berval *bva = NULL, idx;
        char ibuf[32], *ptr;
 
        if ( !start )
@@ -164,10 +164,11 @@ void oidm_unparse( BerVarray *res, OidMacro *start, OidMacro *end, int sys )
 
        /* count the result size */
        i = 0;
-       for ( om=start; om && om!=end; om=LDAP_STAILQ_NEXT(om, som_next)) {
+       for ( om=start; om; om=LDAP_STAILQ_NEXT(om, som_next)) {
                if ( sys && !(om->som_flags & SLAP_OM_HARDCODE)) continue;
                for ( j=0; !BER_BVISNULL(&om->som_names[j]); j++ );
                i += j;
+               if ( om == end ) break;
        }
        num = i;
        if (!i) return;
@@ -179,11 +180,11 @@ void oidm_unparse( BerVarray *res, OidMacro *start, OidMacro *end, int sys )
                idx.bv_len = 0;
                ibuf[0] = '\0';
        }
-       for ( i=0,om=start; om && om!=end; om=LDAP_STAILQ_NEXT(om, som_next)) {
+       for ( i=0,om=start; om; om=LDAP_STAILQ_NEXT(om, som_next)) {
                if ( sys && !(om->som_flags & SLAP_OM_HARDCODE)) continue;
                for ( j=0; !BER_BVISNULL(&om->som_names[j]); i++,j++ ) {
                        if ( !sys ) {
-                               idx.bv_len = sprintf(idx.bv_val, "{%02d}", i );
+                               idx.bv_len = sprintf(idx.bv_val, "{%d}", i );
                        }
                        bva[i].bv_len = idx.bv_len + om->som_names[j].bv_len +
                                om->som_subs[j].bv_len + 1;
@@ -194,6 +195,7 @@ void oidm_unparse( BerVarray *res, OidMacro *start, OidMacro *end, int sys )
                        strcpy( ptr, om->som_subs[j].bv_val );
                }
                if ( i>=num ) break;
+               if ( om == end ) break;
        }
        *res = bva;
 }