Index: lib/libc/locale/collate.c =================================================================== --- lib/libc/locale/collate.c +++ lib/libc/locale/collate.c @@ -41,9 +41,10 @@ #include "namespace.h" -#include -#include +#include #include +#include +#include #include #include @@ -55,7 +56,6 @@ #include #include "un-namespace.h" -#include "endian.h" #include "collate.h" #include "setlocale.h" #include "ldpart.h" @@ -162,7 +162,7 @@ if ((info->directive_count < 1) || (info->directive_count >= COLL_WEIGHTS_MAX) || - ((chains = BSWAP(info->chain_count)) < 0)) { + ((chains = be32toh(info->chain_count)) < 0)) { (void) munmap(map, sbuf.st_size); errno = EINVAL; return (_LDP_ERROR); @@ -170,9 +170,9 @@ i = (sizeof (collate_char_t) * (UCHAR_MAX + 1)) + (sizeof (collate_chain_t) * chains) + - (sizeof (collate_large_t) * BSWAP(info->large_count)); + (sizeof (collate_large_t) * be32toh(info->large_count)); for (z = 0; z < info->directive_count; z++) { - i += sizeof (collate_subst_t) * BSWAP(info->subst_count[z]); + i += sizeof (collate_subst_t) * be32toh(info->subst_count[z]); } if (i != (sbuf.st_size - (TMP - map))) { (void) munmap(map, sbuf.st_size); @@ -185,9 +185,10 @@ TMP += sizeof (collate_char_t) * (UCHAR_MAX + 1); for (z = 0; z < info->directive_count; z++) { - if (BSWAP(info->subst_count[z]) > 0) { + if (be32toh(info->subst_count[z]) > 0) { table->subst_table[z] = (void *)TMP; - TMP += BSWAP(info->subst_count[z]) * sizeof (collate_subst_t); + TMP += be32toh(info->subst_count[z]) * + sizeof(collate_subst_t); } else { table->subst_table[z] = NULL; } @@ -198,7 +199,7 @@ TMP += chains * sizeof (collate_chain_t); } else table->chain_pri_table = NULL; - if (BSWAP(info->large_count) > 0) + if (be32toh(info->large_count) > 0) table->large_pri_table = (void *)TMP; else table->large_pri_table = NULL; @@ -211,7 +212,7 @@ substsearch(struct xlocale_collate *table, const wchar_t key, int pass) { const collate_subst_t *p; - int n = BSWAP(table->info->subst_count[pass]); + int n = be32toh(table->info->subst_count[pass]); if (n == 0) return (NULL); @@ -223,7 +224,7 @@ return (NULL); p = table->subst_table[pass] + (key & ~COLLATE_SUBST_PRIORITY); - assert(BSWAP(p->key) == key); + assert(be32toh(p->key) == key); return (p->pri); } @@ -232,7 +233,7 @@ chainsearch(struct xlocale_collate *table, const wchar_t *key, int *len) { int low = 0; - int high = BSWAP(table->info->chain_count) - 1; + int high = be32toh(table->info->chain_count) - 1; int next, compar, l; collate_chain_t *p; collate_chain_t *tab = table->chain_pri_table; @@ -243,7 +244,7 @@ while (low <= high) { next = (low + high) / 2; p = tab + next; - compar = *key - le16toh(*p->str); + compar = *key - be32toh(*p->str); if (compar == 0) { l = wcsnlen(p->str, COLLATE_STR_LEN); compar = wcsncmp(key, p->str, l); @@ -264,7 +265,7 @@ largesearch(struct xlocale_collate *table, const wchar_t key) { int low = 0; - int high = BSWAP(table->info->large_count) - 1; + int high = be32toh(table->info->large_count) - 1; int next, compar; collate_large_t *p; collate_large_t *tab = table->large_pri_table; @@ -275,7 +276,7 @@ while (low <= high) { next = (low + high) / 2; p = tab + next; - compar = key - BSWAP(p->val); + compar = key - be32toh(p->val); if (compar == 0) return (p); if (compar > 0) @@ -340,15 +341,15 @@ * Character is a small (8-bit) character. * We just look these up directly for speed. */ - *pri = BSWAP(table->char_pri_table[*t].pri[which]); + *pri = be32toh(table->char_pri_table[*t].pri[which]); - } else if ((BSWAP(table->info->large_count) > 0) && + } else if ((be32toh(table->info->large_count) > 0) && ((match = largesearch(table, *t)) != NULL)) { /* * Character was found in the extended table. */ - *pri = BSWAP(match->pri.pri[which]); + *pri = be32toh(match->pri.pri[which]); } else { /* @@ -358,7 +359,7 @@ /* Mask off sign bit to prevent ordering confusion. */ *pri = (*t & COLLATE_MAX_PRIORITY); } else { - *pri = BSWAP(table->info->undef_pri[which]); + *pri = be32toh(table->info->undef_pri[which]); } /* No substitutions for undefined characters! */ return; @@ -377,9 +378,9 @@ * code ensures this for us. */ if ((sptr = substsearch(table, *pri, which)) != NULL) { - if ((*pri = BSWAP(*sptr)) > 0) { + if ((*pri = be32toh(*sptr)) > 0) { sptr++; - *state = BSWAP(*sptr) ? sptr : NULL; + *state = be32toh(*sptr) ? sptr : NULL; } } @@ -521,7 +522,7 @@ xfrm(struct xlocale_collate *table, unsigned char *p, int pri, int pass) { /* we use unsigned to ensure zero fill on right shift */ - uint32_t val = BSWAP((uint32_t)table->info->pri_count[pass]); + uint32_t val = be32toh((uint32_t)table->info->pri_count[pass]); int nc = 0; while (val) { @@ -681,7 +682,7 @@ e = -1; if (*str <= UCHAR_MAX) e = table->char_pri_table[*str].pri[0]; - else if (BSWAP(table->info->large_count) > 0) { + else if (be32toh(table->info->large_count) > 0) { collate_large_t *match_large; match_large = largesearch(table, *str); if (match_large) @@ -691,7 +692,7 @@ return (1); return (e > 0 ? e : 0); } - if (BSWAP(table->info->chain_count) > 0) { + if (be32toh(table->info->chain_count) > 0) { wchar_t name[COLLATE_STR_LEN]; collate_chain_t *match_chain; int clen; Index: lib/libc/locale/endian.h =================================================================== --- lib/libc/locale/endian.h +++ lib/libc/locale/endian.h @@ -1,52 +0,0 @@ -/*- - * Copyright (c) 2016 Ruslan Bukin - * All rights reserved. - * - * Portions of this software were developed by SRI International and the - * University of Cambridge Computer Laboratory under DARPA/AFRL contract - * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme. - * - * Portions of this software were developed by the University of Cambridge - * Computer Laboratory as part of the CTSRD Project, with support from the - * UK Higher Education Innovation Fund (HEIF). - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include - -/* - * We assume locale files were generated on EL machine - * (e.g. during cross build on amd64 host), but used on EB - * machine (e.g. MIPS64EB), so convert it to host endianness. - * - * TODO: detect host endianness on the build machine and use - * correct macros here. - */ - -#if BYTE_ORDER == BIG_ENDIAN && defined(__mips__) -#define BSWAP(x) le32toh(x) -#else -#define BSWAP(x) x -#endif Index: lib/libc/locale/rune.c =================================================================== --- lib/libc/locale/rune.c +++ lib/libc/locale/rune.c @@ -41,20 +41,22 @@ __FBSDID("$FreeBSD$"); #include "namespace.h" -#include + +#include +#include +#include +#include + #include +#include #include #include -#include #include -#include -#include -#include -#include +#include #include + #include "un-namespace.h" -#include "endian.h" #include "runefile.h" _RuneLocale * @@ -110,29 +112,29 @@ } runetype_ext_ranges = (_FileRuneEntry *)variable; - variable = runetype_ext_ranges + BSWAP(frl->runetype_ext_nranges); + variable = runetype_ext_ranges + be32toh(frl->runetype_ext_nranges); if (variable > lastp) { goto invalid; } maplower_ext_ranges = (_FileRuneEntry *)variable; - variable = maplower_ext_ranges + BSWAP(frl->maplower_ext_nranges); + variable = maplower_ext_ranges + be32toh(frl->maplower_ext_nranges); if (variable > lastp) { goto invalid; } mapupper_ext_ranges = (_FileRuneEntry *)variable; - variable = mapupper_ext_ranges + BSWAP(frl->mapupper_ext_nranges); + variable = mapupper_ext_ranges + be32toh(frl->mapupper_ext_nranges); if (variable > lastp) { goto invalid; } frr = runetype_ext_ranges; - for (x = 0; x < BSWAP(frl->runetype_ext_nranges); ++x) { + for (x = 0; x < be32toh(frl->runetype_ext_nranges); ++x) { uint32_t *types; - if (BSWAP(frr[x].map) == 0) { - int len = BSWAP(frr[x].max) - BSWAP(frr[x].min) + 1; + if (be32toh(frr[x].map) == 0) { + int len = be32toh(frr[x].max) - be32toh(frr[x].min) + 1; types = variable; variable = types + len; runetype_ext_len += len; @@ -142,7 +144,7 @@ } } - if ((char *)variable + BSWAP(frl->variable_len) > (char *)lastp) { + if ((char *)variable + be32toh(frl->variable_len) > (char *)lastp) { goto invalid; } @@ -150,10 +152,10 @@ * Convert from disk format to host format. */ data = malloc(sizeof(_RuneLocale) + - (BSWAP(frl->runetype_ext_nranges) + BSWAP(frl->maplower_ext_nranges) + - BSWAP(frl->mapupper_ext_nranges)) * sizeof(_RuneEntry) + + (be32toh(frl->runetype_ext_nranges) + be32toh(frl->maplower_ext_nranges) + + be32toh(frl->mapupper_ext_nranges)) * sizeof(_RuneEntry) + runetype_ext_len * sizeof(*rr->__types) + - BSWAP(frl->variable_len)); + be32toh(frl->variable_len)); if (data == NULL) { saverr = errno; munmap(fdata, sb.st_size); @@ -167,15 +169,15 @@ memcpy(rl->__magic, _RUNE_MAGIC_1, sizeof(rl->__magic)); memcpy(rl->__encoding, frl->encoding, sizeof(rl->__encoding)); - rl->__variable_len = BSWAP(frl->variable_len); - rl->__runetype_ext.__nranges = BSWAP(frl->runetype_ext_nranges); - rl->__maplower_ext.__nranges = BSWAP(frl->maplower_ext_nranges); - rl->__mapupper_ext.__nranges = BSWAP(frl->mapupper_ext_nranges); + rl->__variable_len = be32toh(frl->variable_len); + rl->__runetype_ext.__nranges = be32toh(frl->runetype_ext_nranges); + rl->__maplower_ext.__nranges = be32toh(frl->maplower_ext_nranges); + rl->__mapupper_ext.__nranges = be32toh(frl->mapupper_ext_nranges); for (x = 0; x < _CACHED_RUNES; ++x) { - rl->__runetype[x] = BSWAP(frl->runetype[x]); - rl->__maplower[x] = BSWAP(frl->maplower[x]); - rl->__mapupper[x] = BSWAP(frl->mapupper[x]); + rl->__runetype[x] = be32toh(frl->runetype[x]); + rl->__maplower[x] = be32toh(frl->maplower[x]); + rl->__mapupper[x] = be32toh(frl->mapupper[x]); } rl->__runetype_ext.__ranges = (_RuneEntry *)rl->__variable; @@ -190,15 +192,15 @@ rl->__variable = rl->__mapupper_ext.__ranges + rl->__mapupper_ext.__nranges; - variable = mapupper_ext_ranges + BSWAP(frl->mapupper_ext_nranges); + variable = mapupper_ext_ranges + be32toh(frl->mapupper_ext_nranges); frr = runetype_ext_ranges; rr = rl->__runetype_ext.__ranges; for (x = 0; x < rl->__runetype_ext.__nranges; ++x) { uint32_t *types; - rr[x].__min = BSWAP(frr[x].min); - rr[x].__max = BSWAP(frr[x].max); - rr[x].__map = BSWAP(frr[x].map); + rr[x].__min = be32toh(frr[x].min); + rr[x].__max = be32toh(frr[x].max); + rr[x].__map = be32toh(frr[x].map); if (rr[x].__map == 0) { int len = rr[x].__max - rr[x].__min + 1; types = variable; @@ -214,17 +216,17 @@ frr = maplower_ext_ranges; rr = rl->__maplower_ext.__ranges; for (x = 0; x < rl->__maplower_ext.__nranges; ++x) { - rr[x].__min = BSWAP(frr[x].min); - rr[x].__max = BSWAP(frr[x].max); - rr[x].__map = BSWAP(frr[x].map); + rr[x].__min = be32toh(frr[x].min); + rr[x].__max = be32toh(frr[x].max); + rr[x].__map = be32toh(frr[x].map); } frr = mapupper_ext_ranges; rr = rl->__mapupper_ext.__ranges; for (x = 0; x < rl->__mapupper_ext.__nranges; ++x) { - rr[x].__min = BSWAP(frr[x].min); - rr[x].__max = BSWAP(frr[x].max); - rr[x].__map = BSWAP(frr[x].map); + rr[x].__min = be32toh(frr[x].min); + rr[x].__max = be32toh(frr[x].max); + rr[x].__map = be32toh(frr[x].map); } memcpy(rl->__variable, variable, rl->__variable_len); Index: targets/pseudo/userland/Makefile.depend =================================================================== --- targets/pseudo/userland/Makefile.depend +++ targets/pseudo/userland/Makefile.depend @@ -246,6 +246,7 @@ usr.bin/lex/lib \ usr.bin/limits \ usr.bin/locale \ + usr.bin/localedef \ usr.bin/locate/bigram \ usr.bin/locate/code \ usr.bin/locate/locate \ Index: usr.bin/localedef/collate.c =================================================================== --- usr.bin/localedef/collate.c +++ usr.bin/localedef/collate.c @@ -1,5 +1,5 @@ /*- - * Copyright 2010 Nexenta Systems, Inc. All rights reserved. + * Copyright 2018 Nexenta Systems, Inc. * Copyright 2015 John Marino * * This source code is derived from the illumos localedef command, and @@ -34,8 +34,9 @@ #include __FBSDID("$FreeBSD$"); -#include +#include #include +#include #include #include @@ -253,6 +254,9 @@ static int32_t pri_ignore; static collate_info_t collinfo; +static int32_t subst_count[COLL_WEIGHTS_MAX]; +static int32_t chain_count; +static int32_t large_count; static collpri_t *prilist = NULL; static int numpri = 0; @@ -1080,7 +1084,7 @@ wchar_t *os1 = s1; n++; - while (--n > 0 && (*s1++ = *s2++) != 0) + while (--n > 0 && (*s1++ = htobe32(*s2++)) != 0) continue; if (n > 0) while (--n > 0) @@ -1165,13 +1169,13 @@ if (resolve_pri(pri_undefined[i]) == -1) { set_pri(pri_undefined[i], -1, RESOLVED); /* they collate at the end of everything else */ - collinfo.undef_pri[i] = COLLATE_MAX_PRIORITY; + collinfo.undef_pri[i] = htobe32(COLLATE_MAX_PRIORITY); } - collinfo.pri_count[i] = nweight[i]; + collinfo.pri_count[i] = htobe32(nweight[i]); } - collinfo.pri_count[NUM_WT] = max_wide(); - collinfo.undef_pri[NUM_WT] = COLLATE_MAX_PRIORITY; + collinfo.pri_count[NUM_WT] = htobe32(max_wide()); + collinfo.undef_pri[NUM_WT] = htobe32(COLLATE_MAX_PRIORITY); collinfo.directive[NUM_WT] = DIRECTIVE_UNDEFINED; /* @@ -1180,19 +1184,20 @@ for (i = 0; i <= UCHAR_MAX; i++) { if ((cc = get_collchar(i, 0)) != NULL) { for (j = 0; j < NUM_WT; j++) { - chars[i].pri[j] = get_weight(cc->ref[j], j); + chars[i].pri[j] = + htobe32(get_weight(cc->ref[j], j)); } } else { for (j = 0; j < NUM_WT; j++) { chars[i].pri[j] = - get_weight(pri_undefined[j], j); + htobe32(get_weight(pri_undefined[j], j)); } /* * Per POSIX, for undefined characters, we * also have to add a last item, which is the * character code. */ - chars[i].pri[NUM_WT] = i; + chars[i].pri[NUM_WT] = htobe32(i); } } @@ -1203,7 +1208,7 @@ collate_subst_t *st = NULL; subst_t *temp; RB_COUNT(temp, substs, &substs[i], n); - collinfo.subst_count[i] = n; + subst_count[i] = n; if ((st = calloc(n, sizeof(collate_subst_t))) == NULL) { fprintf(stderr, "out of memory"); return; @@ -1217,12 +1222,14 @@ if (st[n].key != (n | COLLATE_SUBST_PRIORITY)) { INTERR; } + st[n].key = htobe32(st[n].key); for (j = 0; sb->ref[j]; j++) { - st[n].pri[j] = get_weight(sb->ref[j], i); + st[n].pri[j] = htobe32(get_weight(sb->ref[j], + i)); } n++; } - if (n != collinfo.subst_count[i]) + if (n != subst_count[i]) INTERR; subst[i] = st; } @@ -1231,9 +1238,8 @@ /* * Chains, i.e. collating elements */ - RB_NUMNODES(collelem_t, elem_by_expand, &elem_by_expand, - collinfo.chain_count); - chain = calloc(collinfo.chain_count, sizeof(collate_chain_t)); + RB_NUMNODES(collelem_t, elem_by_expand, &elem_by_expand, chain_count); + chain = calloc(chain_count, sizeof(collate_chain_t)); if (chain == NULL) { fprintf(stderr, "out of memory"); return; @@ -1242,11 +1248,11 @@ RB_FOREACH(ce, elem_by_expand, &elem_by_expand) { (void) wsncpy(chain[n].str, ce->expand, COLLATE_STR_LEN); for (i = 0; i < NUM_WT; i++) { - chain[n].pri[i] = get_weight(ce->ref[i], i); + chain[n].pri[i] = htobe32(get_weight(ce->ref[i], i)); } n++; } - if (n != collinfo.chain_count) + if (n != chain_count) INTERR; /* @@ -1273,12 +1279,12 @@ /* if undefined, then all priorities are */ INTERR; } else { - large[i].pri.pri[j] = pri; + large[i].pri.pri[j] = htobe32(pri); } } if (!undef) { - large[i].val = cc->wc; - collinfo.large_count = i++; + large[i].val = htobe32(cc->wc); + large_count = i++; } } @@ -1288,6 +1294,11 @@ /* Time to write the entire data set out */ + for (i = 0; i < NUM_WT; i++) + collinfo.subst_count[i] = htobe32(subst_count[i]); + collinfo.chain_count = htobe32(chain_count); + collinfo.large_count = htobe32(large_count); + if ((wr_category(vers, COLLATE_STR_LEN, f) < 0) || (wr_category(&collinfo, sizeof (collinfo), f) < 0) || (wr_category(&chars, sizeof (chars), f) < 0)) { @@ -1295,16 +1306,16 @@ } for (i = 0; i < NUM_WT; i++) { - sz = sizeof (collate_subst_t) * collinfo.subst_count[i]; + sz = sizeof (collate_subst_t) * subst_count[i]; if (wr_category(subst[i], sz, f) < 0) { return; } } - sz = sizeof (collate_chain_t) * collinfo.chain_count; + sz = sizeof (collate_chain_t) * chain_count; if (wr_category(chain, sz, f) < 0) { return; } - sz = sizeof (collate_large_t) * collinfo.large_count; + sz = sizeof (collate_large_t) * large_count; if (wr_category(large, sz, f) < 0) { return; } Index: usr.bin/localedef/ctype.c =================================================================== --- usr.bin/localedef/ctype.c +++ usr.bin/localedef/ctype.c @@ -1,5 +1,5 @@ /*- - * Copyright 2011 Nexenta Systems, Inc. All rights reserved. + * Copyright 2018 Nexenta Systems, Inc. * Copyright 2012 Garrett D'Amore All rights reserved. * Copyright 2015 John Marino * @@ -35,13 +35,14 @@ #include __FBSDID("$FreeBSD$"); +#include #include +#include #include #include #include #include -#include #include #include #include @@ -296,10 +297,16 @@ _FileRuneEntry *lo = NULL; _FileRuneEntry *up = NULL; wchar_t wc; + uint32_t runetype_ext_nranges; + uint32_t maplower_ext_nranges; + uint32_t mapupper_ext_nranges; (void) memset(&rl, 0, sizeof (rl)); + runetype_ext_nranges = 0; last_ct = NULL; + maplower_ext_nranges = 0; last_lo = NULL; + mapupper_ext_nranges = 0; last_up = NULL; if ((f = open_category()) == NULL) @@ -312,8 +319,8 @@ * Initialize the identity map. */ for (wc = 0; (unsigned)wc < _CACHED_RUNES; wc++) { - rl.maplower[wc] = wc; - rl.mapupper[wc] = wc; + rl.maplower[wc] = htobe32(wc); + rl.mapupper[wc] = htobe32(wc); } RB_FOREACH(ctn, ctypes, &ctypes) { @@ -399,39 +406,39 @@ * upper/lower case, then we identity map it. */ if ((unsigned)wc < _CACHED_RUNES) { - rl.runetype[wc] = ctn->ctype; + rl.runetype[wc] = htobe32(ctn->ctype); if (ctn->tolower) - rl.maplower[wc] = ctn->tolower; + rl.maplower[wc] = htobe32(ctn->tolower); if (ctn->toupper) - rl.mapupper[wc] = ctn->toupper; + rl.mapupper[wc] = htobe32(ctn->toupper); continue; } if ((last_ct != NULL) && (last_ct->ctype == ctn->ctype) && (last_ct->wc + 1 == wc)) { - ct[rl.runetype_ext_nranges-1].max = wc; + ct[runetype_ext_nranges - 1].max = htobe32(wc); } else { - rl.runetype_ext_nranges++; - ct = realloc(ct, - sizeof (*ct) * rl.runetype_ext_nranges); - ct[rl.runetype_ext_nranges - 1].min = wc; - ct[rl.runetype_ext_nranges - 1].max = wc; - ct[rl.runetype_ext_nranges - 1].map = ctn->ctype; + runetype_ext_nranges++; + ct = realloc(ct, sizeof (*ct) * runetype_ext_nranges); + ct[runetype_ext_nranges - 1].min = htobe32(wc); + ct[runetype_ext_nranges - 1].max = htobe32(wc); + ct[runetype_ext_nranges - 1].map = + htobe32(ctn->ctype); } last_ct = ctn; if (ctn->tolower == 0) { last_lo = NULL; } else if ((last_lo != NULL) && (last_lo->tolower + 1 == ctn->tolower)) { - lo[rl.maplower_ext_nranges-1].max = wc; + lo[maplower_ext_nranges - 1].max = htobe32(wc); last_lo = ctn; } else { - rl.maplower_ext_nranges++; - lo = realloc(lo, - sizeof (*lo) * rl.maplower_ext_nranges); - lo[rl.maplower_ext_nranges - 1].min = wc; - lo[rl.maplower_ext_nranges - 1].max = wc; - lo[rl.maplower_ext_nranges - 1].map = ctn->tolower; + maplower_ext_nranges++; + lo = realloc(lo, sizeof (*lo) * maplower_ext_nranges); + lo[maplower_ext_nranges - 1].min = htobe32(wc); + lo[maplower_ext_nranges - 1].max = htobe32(wc); + lo[maplower_ext_nranges - 1].map = + htobe32(ctn->tolower); last_lo = ctn; } @@ -439,23 +446,26 @@ last_up = NULL; } else if ((last_up != NULL) && (last_up->toupper + 1 == ctn->toupper)) { - up[rl.mapupper_ext_nranges-1].max = wc; + up[mapupper_ext_nranges-1].max = htobe32(wc); last_up = ctn; } else { - rl.mapupper_ext_nranges++; - up = realloc(up, - sizeof (*up) * rl.mapupper_ext_nranges); - up[rl.mapupper_ext_nranges - 1].min = wc; - up[rl.mapupper_ext_nranges - 1].max = wc; - up[rl.mapupper_ext_nranges - 1].map = ctn->toupper; + mapupper_ext_nranges++; + up = realloc(up, sizeof (*up) * mapupper_ext_nranges); + up[mapupper_ext_nranges - 1].min = htobe32(wc); + up[mapupper_ext_nranges - 1].max = htobe32(wc); + up[mapupper_ext_nranges - 1].map = + htobe32(ctn->toupper); last_up = ctn; } } + rl.runetype_ext_nranges = htobe32(runetype_ext_nranges); + rl.maplower_ext_nranges = htobe32(maplower_ext_nranges); + rl.mapupper_ext_nranges = htobe32(mapupper_ext_nranges); if ((wr_category(&rl, sizeof (rl), f) < 0) || - (wr_category(ct, sizeof (*ct) * rl.runetype_ext_nranges, f) < 0) || - (wr_category(lo, sizeof (*lo) * rl.maplower_ext_nranges, f) < 0) || - (wr_category(up, sizeof (*up) * rl.mapupper_ext_nranges, f) < 0)) { + (wr_category(ct, sizeof (*ct) * runetype_ext_nranges, f) < 0) || + (wr_category(lo, sizeof (*lo) * maplower_ext_nranges, f) < 0) || + (wr_category(up, sizeof (*up) * mapupper_ext_nranges, f) < 0)) { return; }