if( PR_SUCCESS != nssUTF8_Length(rv, &len) ) {
len = nssUTF8_Length(rv, &status); if( PR_SUCCESS != status || len == 0 ) {
nss_attr_to_utf8(  NSSArena *arenaOpt,  const NSSOID *oid,  NSSItem *item,  nssStringType *stringForm){  NSSUTF8 *rv = (NSSUTF8 *)NULL;  PRUint32 i;  const struct nss_attribute_data_str *which =     (struct nss_attribute_data_str *)NULL;  PRUint32 len = 0;  for( i = 0; i < nss_attribute_data_quantity; i++ ) {    if( *(nss_attribute_data[ i ].oid) == oid ) {      which = &nss_attribute_data[i];      break;    }  }  if( (struct nss_attribute_data_str *)NULL == which ) {    /* Unknown OID.  Encode it as hex. */    PRUint8 *c;    PRUint8 *d = (PRUint8 *)item->data;    PRUint32 amt = item->size;    if( item->size >= 0x7FFFFFFF ) {      nss_SetError(NSS_ERROR_INVALID_STRING);      return (NSSUTF8 *)NULL;    }    len = 1 + (item->size * 2) + 1; /* '#' + hex + '\0' */    rv = (NSSUTF8 *)nss_ZAlloc(arenaOpt, len);    if( (NSSUTF8 *)NULL == rv ) {      return (NSSUTF8 *)NULL;    }    c = (PRUint8 *)rv;    *c++ = '#'; /* XXX fgmr check this */    while( amt > 0 ) {      static char hex[16] = "0123456789ABCDEF";      *c++ = hex[ ((*d) & 0xf0) >> 4 ];      *c++ = hex[ ((*d) & 0x0f)      ];    }    /* *c = '\0'; nss_ZAlloc, remember */    *stringForm = nssStringType_Unknown; /* force exact comparison */  } else {    rv = nssUTF8_CreateFromBER(arenaOpt, which->stringType,                                (NSSBER *)item);    if( (NSSUTF8 *)NULL == rv ) {      return (NSSUTF8 *)NULL;    }    if( PR_SUCCESS != nssUTF8_Length(rv, &len) ) {      nss_ZFreeIf(rv);      return (NSSUTF8 *)NULL;    }    *stringForm = nss_attr_underlying_string_form(which->stringType,                                                  item->data);  }  return rv;}