define macros for appropriate sizing of lutil buffers

This commit is contained in:
Pierangelo Masarati 2002-08-31 10:48:02 +00:00
parent e2ec62f09f
commit aea52e5bc9
7 changed files with 23 additions and 16 deletions

View 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 );

View 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");

View 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;

View 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 );

View 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;

View 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;

View 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 );