tmpbuf[0] =  (entry->nemailAddrs >> 8) & 0xff; tmpbuf[1] =  entry->nemailAddrs  & 0xff;
int j; tmpbuf[0] =  (unsigned char)(entry->nemailAddrs >> 8); tmpbuf[1] =  (unsigned char)entry->nemailAddrs;
EncodeDBSubjectEntry(certDBEntrySubject *entry, PRArenaPool *arena,		     SECItem *dbitem){    unsigned char *buf;    int len;    unsigned int ncerts;    unsigned int i;    unsigned char *tmpbuf;    unsigned int nnlen = 0;    unsigned int eaddrslen = 0;    int keyidoff;    SECItem *certKeys;    SECItem *keyIDs;        if ( entry->nickname ) {	nnlen = PORT_Strlen(entry->nickname) + 1;    }    if ( entry->emailAddrs ) {	eaddrslen = 2;	for (i=0; i < entry->nemailAddrs; i++) {	    eaddrslen += PORT_Strlen(entry->emailAddrs[i]) + 1 + 2;	}    }    ncerts = entry->ncerts;        /* compute the length of the entry */    keyidoff = DB_SUBJECT_ENTRY_HEADER_LEN + nnlen ;    len = keyidoff + 4 * ncerts + eaddrslen;    for ( i = 0; i < ncerts; i++ ) {	len += entry->certKeys[i].len;	len += entry->keyIDs[i].len;    }        /* allocate space for encoded database record, including space     * for low level header     */    dbitem->len = len + SEC_DB_ENTRY_HEADER_LEN;        dbitem->data = (unsigned char *)PORT_ArenaAlloc(arena, dbitem->len);    if ( dbitem->data == NULL) {	PORT_SetError(SEC_ERROR_NO_MEMORY);	goto loser;    }        /* fill in database record */    buf = &dbitem->data[SEC_DB_ENTRY_HEADER_LEN];        buf[0] = ( ncerts >> 8 ) & 0xff;    buf[1] = ncerts & 0xff;    buf[2] = ( nnlen >> 8 ) & 0xff;    buf[3] = nnlen & 0xff;    /* v7 email field is NULL in v8 */    buf[4] = 0;    buf[5] = 0;    PORT_Memcpy(&buf[DB_SUBJECT_ENTRY_HEADER_LEN], entry->nickname, nnlen);        for ( i = 0; i < ncerts; i++ ) {	certKeys = entry->certKeys;	keyIDs = entry->keyIDs;	buf[keyidoff+i*2] = ( certKeys[i].len >> 8 ) & 0xff;	buf[keyidoff+1+i*2] = certKeys[i].len & 0xff;	buf[keyidoff+ncerts*2+i*2] = ( keyIDs[i].len >> 8 ) & 0xff;	buf[keyidoff+1+ncerts*2+i*2] = keyIDs[i].len & 0xff;    }        /* temp pointer used to stuff certkeys and keyids into the buffer */    tmpbuf = &buf[keyidoff+ncerts*4];    for ( i = 0; i < ncerts; i++ ) {	certKeys = entry->certKeys;	PORT_Memcpy(tmpbuf, certKeys[i].data, certKeys[i].len);	tmpbuf = tmpbuf + certKeys[i].len;    }        for ( i = 0; i < ncerts; i++ ) {	keyIDs = entry->keyIDs;	PORT_Memcpy(tmpbuf, keyIDs[i].data, keyIDs[i].len);	tmpbuf = tmpbuf + keyIDs[i].len;    }    if (entry->emailAddrs) {	tmpbuf[0] =  (entry->nemailAddrs >> 8) & 0xff;	tmpbuf[1] =  entry->nemailAddrs  & 0xff;	tmpbuf += 2;	for (i=0; i < entry->nemailAddrs; i++) {	    int nameLen = PORT_Strlen(entry->emailAddrs[i]) + 1;	    tmpbuf[0] =  (nameLen >> 8) & 0xff;	    tmpbuf[1] =  nameLen & 0xff;	    tmpbuf += 2;	    PORT_Memcpy(tmpbuf,entry->emailAddrs[i],nameLen);	    tmpbuf +=nameLen;	}    }    PORT_Assert(tmpbuf == &buf[len]);        return(SECSuccess);loser:    return(SECFailure);}