From 822bfc3670e04b66c3ecbd1f917a5dd8d7a16ce2 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Mon, 2 Oct 2000 17:43:06 +0000 Subject: [PATCH] Rework stringal decode to return { NULL, 0 } bv's instead of { "", 0 } when len is 0. --- libraries/liblber/decode.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/libraries/liblber/decode.c b/libraries/liblber/decode.c index ef12bf46d6..e55354f5e1 100644 --- a/libraries/liblber/decode.c +++ b/libraries/liblber/decode.c @@ -297,23 +297,33 @@ ber_get_stringal( BerElement *ber, struct berval **bv ) if ( (tag = ber_skip_tag( ber, &len )) == LBER_DEFAULT ) { *bv = NULL; - return( LBER_DEFAULT ); + return LBER_DEFAULT; } - if ( (*bv = (struct berval *) LBER_MALLOC( sizeof(struct berval) )) == NULL ) - return( LBER_DEFAULT ); + *bv = (struct berval *) LBER_MALLOC( sizeof(struct berval) ); + if ( *bv == NULL ) { + return LBER_DEFAULT; + } - if ( ((*bv)->bv_val = (char *) LBER_MALLOC( len + 1 )) == NULL ) { + if( len == 0 ) { + (*bv)->bv_val = NULL; + (*bv)->bv_len = 0; + return tag; + } + + (*bv)->bv_val = (char *) LBER_MALLOC( len + 1 ); + if ( (*bv)->bv_val == NULL ) { LBER_FREE( *bv ); *bv = NULL; - return( LBER_DEFAULT ); + return LBER_DEFAULT; } if ( (ber_len_t) ber_read( ber, (*bv)->bv_val, len ) != len ) { ber_bvfree( *bv ); *bv = NULL; - return( LBER_DEFAULT ); + return LBER_DEFAULT; } + ((*bv)->bv_val)[len] = '\0'; (*bv)->bv_len = len; -- 2.39.5