-/*
- * Copyright 2000-2003 The OpenLDAP Foundation
- * COPYING RESTRICTIONS APPLY. See COPYRIGHT File in top level directory
- * of this package for details.
+/* $OpenLDAP$ */
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1998-2007 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
*/
#include "portable.h"
+#include <ac/bytes.h>
#include <ac/ctype.h>
#include <ac/string.h>
#include <ac/stdlib.h>
{
int i, j, len, clen, outpos, ucsoutlen, outsize, last;
char *out, *outtmp, *s;
- unsigned long *ucs, *p, *ucsout;
+ ac_uint4 *ucs, *p, *ucsout;
static unsigned char mask[] = {
0, 0x7f, 0x1f, 0x0f, 0x07, 0x03, 0x01 };
last = i;
+ /* Allocate more space in out if necessary */
+ if (len - i >= outsize - outpos) {
+ outsize += 1 + ((len - i) - (outsize - outpos));
+ outtmp = (char *) realloc(out, outsize);
+ if (outtmp == NULL) {
+ free(out);
+ free(ucs);
+ return NULL;
+ }
+ out = outtmp;
+ }
+
/* s[i] is ascii */
/* finish off everything up to char before next non-ascii */
for ( i++; (i < len) && LDAP_UTF8_ISASCII(s + i); i++ ) {
{
int i, l1, l2, len, ulen, res = 0;
char *s1, *s2, *done;
- unsigned long *ucs, *ucsout1, *ucsout2;
+ ac_uint4 *ucs, *ucsout1, *ucsout2;
unsigned casefold = flags & LDAP_UTF8_CASEFOLD;
unsigned norm1 = flags & LDAP_UTF8_ARG1NFC;
/*
* XXYYZ: we convert to ucs4 even though -llunicode
- * expects ucs2 in an unsigned long
+ * expects ucs2 in an ac_uint4
*/
/* convert and normalize 1st string */
l1 = ulen;
ucs = malloc( l2 * sizeof(*ucs) );
if ( ucs == NULL ) {
+ free( ucsout1 );
return l1 > l2 ? 1 : -1; /* what to do??? */
}
} else {