]> git.sur5r.net Git - openldap/commitdiff
define macros for appropriate sizing of lutil buffers
authorPierangelo Masarati <ando@openldap.org>
Sat, 31 Aug 2002 10:48:02 +0000 (10:48 +0000)
committerPierangelo Masarati <ando@openldap.org>
Sat, 31 Aug 2002 10:48:02 +0000 (10:48 +0000)
include/lutil.h
libraries/liblutil/csn.c
servers/slapd/back-bdb/init.c
servers/slapd/back-monitor/conn.c
servers/slapd/back-monitor/time.c
servers/slapd/modify.c
servers/slapd/tools/slapadd.c

index 4c8f425543b868d5f67c23f476669a7fa46fdce9..4a53306b814cd3a12144a95572c70bdf4eb68324 100644 (file)
@@ -120,6 +120,8 @@ lutil_strncopy LDAP_P(( char *dst, const char *src, size_t n ));
 
 struct tm;
 
+/* use this macro to statically allocate buffer for lutil_gentime */
+#define LDAP_LUTIL_GENTIME_BUFSIZE     22
 LDAP_LUTIL_F( size_t )
 lutil_gentime LDAP_P(( char *s, size_t max, const struct tm *tm ));
 
@@ -133,10 +135,14 @@ LDAP_LUTIL_F( int )
 lutil_pair( ber_socket_t sd[2] );
 
 /* uuid.c */
+/* use this macro to allocate buffer for lutil_uuidstr */
+#define LDAP_LUTIL_UUIDSTR_BUFSIZE     40
 LDAP_LUTIL_F( size_t )
 lutil_uuidstr( char *buf, size_t len );
 
 /* csn.c */
+/* use this macro to allocate buffer for lutil_csnstr */
+#define LDAP_LUTIL_CSNSTR_BUFSIZE      64
 LDAP_LUTIL_F( size_t )
 lutil_csnstr( char *buf, size_t len, unsigned int replica, unsigned int mod );
 
index 0a18918b3bdc20bfe6a576e090d7c3c1b82aea81..752ee35f89a3f2b7f6e656ab0711acd9f827331e 100644 (file)
@@ -65,7 +65,7 @@ lutil_csnstr(char *buf, size_t len, unsigned int replica, unsigned int mod)
 int
 main(int argc, char **argv)
 {
-       char buf[256];
+       char buf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
 
        if ( ! lutil_csnstr( buf, (size_t) 10, 0, 0 ) ) {
                fprintf(stderr, "failed lutil_csnstr\n");
index 978835bd91b895905a271ffc3d9385c663246d25..f5e9b4ead3763da7ace4066997dc0948d45b043c 100644 (file)
@@ -612,7 +612,7 @@ bdb_initialize(
        db_env_set_func_yield( ldap_pvt_thread_yield );
 
        {
-               static char uuidbuf[40];
+               static char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
 
                bdb_uuid.bv_len = lutil_uuidstr( uuidbuf, sizeof( uuidbuf ));
                bdb_uuid.bv_val = uuidbuf;
index 070f8524f9927444ddf5b6b68770355694e3b394..5bbaca74e1bcf43960d501240a5b8f414d841416 100644 (file)
@@ -253,9 +253,9 @@ conn_create(
 {
        struct monitorentrypriv *mp;
        struct tm               *ltm;
-       char                    buf[1024];
-       char                    buf2[22];
-       char                    buf3[22];
+       char                    buf[ 1024 ];
+       char                    buf2[ LDAP_LUTIL_GENTIME_BUFSIZE ];
+       char                    buf3[ LDAP_LUTIL_GENTIME_BUFSIZE ];
 
        struct berval           bv[2];
 
@@ -293,10 +293,10 @@ conn_create(
        ldap_pvt_thread_mutex_lock( &gmtime_mutex );
        
        ltm = gmtime( &c->c_starttime );
-       lutil_gentime( buf2, sizeof(buf2), ltm );
+       lutil_gentime( buf2, sizeof( buf2 ), ltm );
                        
        ltm = gmtime( &c->c_activitytime );
-       lutil_gentime( buf3, sizeof(buf2), ltm );
+       lutil_gentime( buf3, sizeof( buf3 ), ltm );
                        
        ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
 
index 7a950b593431d1e8d34fe6bf68b087c69c56b79c..abc29e366a4624101b3a67fac7de97ee81a08638 100644 (file)
@@ -59,7 +59,7 @@ monitor_subsys_time_init(
        struct monitorentrypriv *mp;
        char                    buf[1024];
        struct tm               *tms;
-       char                    tmbuf[20];
+       char                    tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
 
        /*
         * Note: ltmbuf, ltm are used only if HACK_LOCAL_TIME is defined
@@ -220,7 +220,8 @@ monitor_subsys_time_update(
        Entry                   *e
 )
 {
-       char            stmbuf[20], ctmbuf[20];
+       char            stmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ],
+                       ctmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
        struct tm       *stm, *ctm;
        Attribute       *a;
        ber_len_t       len;
index d0b81b15c7d37299f1dd783ee0e05ab0b384e33f..799aefee9380e3ba8ae87974447aa90a4df82e0b 100644 (file)
@@ -547,8 +547,8 @@ int slap_mods_opattrs(
        char *textbuf, size_t textlen )
 {
        struct berval name, timestamp, csn;
-       char timebuf[22];
-       char csnbuf[64];
+       char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
+       char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
        Modifications *mod;
 
        int mop = op->o_tag == LDAP_REQ_ADD
@@ -603,7 +603,7 @@ int slap_mods_opattrs(
                }
 
                if( SLAP_LASTMOD(be) ) {
-                       char uuidbuf[40];
+                       char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
 
                        tmpval.bv_len = lutil_uuidstr( uuidbuf, sizeof( uuidbuf ) );
                        tmpval.bv_val = uuidbuf;
index e993da5fa8fb9f35aab4c156f8a537dd1887114d..7e6470ca6f54a670d63d4eb5d679a92df356fb2c 100644 (file)
@@ -152,12 +152,12 @@ main( int argc, char **argv )
                if ( SLAP_LASTMOD(be) ) {
                        struct tm *ltm;
                        time_t now = slap_get_time();
-                       char uuidbuf[40];
-                       struct berval vals[2];
+                       char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
+                       struct berval vals[ 2 ];
 
                        struct berval name, timestamp, csn;
-                       char timebuf[22];
-                       char csnbuf[64];
+                       char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
+                       char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
 
                        ltm = gmtime(&now);
                        lutil_gentime( timebuf, sizeof(timebuf), ltm );