/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 1998-2014 The OpenLDAP Foundation.
+ * Copyright 1998-2018 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
void *ctx )
{
int i, j, len, clen, outpos, ucsoutlen, outsize, last;
+ int didnewbv = 0;
char *out, *outtmp, *s;
ac_uint4 *ucs, *p, *ucsout;
if ( !newbv ) {
newbv = ber_memalloc_x( sizeof(struct berval), ctx );
if ( !newbv ) return NULL;
+ didnewbv = 1;
}
/* Should first check to see if string is already in proper
outsize = len + 7;
out = (char *) ber_memalloc_x( outsize, ctx );
if ( out == NULL ) {
+fail:
+ if ( didnewbv )
+ ber_memfree_x( newbv, ctx );
return NULL;
}
outpos = 0;
outsize = len + 7;
out = (char *) ber_memalloc_x( outsize, ctx );
if ( out == NULL ) {
- return NULL;
+ goto fail;
}
outpos = i - 1;
memcpy(out, s, outpos);
outsize = len + 7;
out = (char *) ber_memalloc_x( outsize, ctx );
if ( out == NULL ) {
- return NULL;
+ goto fail;
}
outpos = 0;
i = 0;
p = ucs = ber_memalloc_x( len * sizeof(*ucs), ctx );
if ( ucs == NULL ) {
ber_memfree_x(out, ctx);
- return NULL;
+ goto fail;
}
/* convert character before first non-ascii to ucs-4 */
if ( clen == 0 ) {
ber_memfree_x( ucs, ctx );
ber_memfree_x( out, ctx );
- return NULL;
+ goto fail;
}
if ( clen == 1 ) {
/* ascii */
if ( (s[i] & 0xc0) != 0x80 ) {
ber_memfree_x( ucs, ctx );
ber_memfree_x( out, ctx );
- return NULL;
+ goto fail;
}
*p <<= 6;
*p |= s[i] & 0x3f;
ber_memfree_x( ucsout, ctx );
ber_memfree_x( ucs, ctx );
ber_memfree_x( out, ctx );
- return NULL;
+ goto fail;
}
out = outtmp;
}
if (outtmp == NULL) {
ber_memfree_x( ucs, ctx );
ber_memfree_x( out, ctx );
- return NULL;
+ goto fail;
}
out = outtmp;
}