Module Name: src Committed By: christos Date: Tue Jan 7 21:46:47 UTC 2014
Modified Files: src/external/bsd/nvi/dist/common: conv.c Log Message: handle unaligned accesses To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/external/bsd/nvi/dist/common/conv.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/external/bsd/nvi/dist/common/conv.c diff -u src/external/bsd/nvi/dist/common/conv.c:1.2 src/external/bsd/nvi/dist/common/conv.c:1.3 --- src/external/bsd/nvi/dist/common/conv.c:1.2 Fri Nov 22 10:52:05 2013 +++ src/external/bsd/nvi/dist/common/conv.c Tue Jan 7 16:46:47 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: conv.c,v 1.2 2013/11/22 15:52:05 christos Exp $ */ +/* $NetBSD: conv.c,v 1.3 2014/01/07 21:46:47 christos Exp $ */ /*- * Copyright (c) 1993, 1994 * The Regents of the University of California. All rights reserved. @@ -53,8 +53,10 @@ raw2int(SCR *sp, const char * str, ssize BINC_RETW(NULL, *tostr, *blen, len); *tolen = len; - for (i = 0; i < len; ++i) - (*tostr)[i] = (u_char) str[i]; + for (i = 0; i < len; ++i) { + CHAR_T w = (u_char)str[i]; + memcpy((*tostr) + i, &w, sizeof(**tostr)); + } *dst = cw->bp1; @@ -131,11 +133,15 @@ default_char2int(SCR *sp, const char * s #endif for (i = 0, j = 0; j < len; ) { - n = mbrtowc((*tostr)+i, src+j, len-j, &mbs); + CHAR_T w; + n = mbrtowc(&w, src + j, len - j, &mbs); + memcpy((*tostr) + i, &w, sizeof(**tostr)); /* NULL character converted */ - if (n == (size_t)-2) error = -(len-j); - if (n == (size_t)-1 || n == (size_t)-2) - HANDLE_MBR_ERROR(n, mbs, (*tostr)[i], src[j]); + if (n == (size_t)-2) error = -(len - j); + if (n == (size_t)-1 || n == (size_t)-2) { + HANDLE_MBR_ERROR(n, mbs, w, src[j]); + memcpy((*tostr) + i, &w, sizeof(**tostr)); + } if (n == 0) n = 1; j += n; if (++i >= *blen) { @@ -216,8 +222,11 @@ int2raw(SCR *sp, const CHAR_T * str, ssi BINC_RETC(NULL, *tostr, *blen, len); *tolen = len; - for (i = 0; i < len; ++i) - (*tostr)[i] = str[i]; + for (i = 0; i < len; ++i) { + CHAR_T w; + memcpy(&w, str + i, sizeof(w)); + (*tostr)[i] = w; + } *dst = cw->bp1; @@ -282,9 +291,11 @@ default_int2char(SCR *sp, const CHAR_T * #endif for (i = 0, j = 0; i < (size_t)len; ++i) { - n = wcrtomb(dst+j, str[i], &mbs); + CHAR_T w; + memcpy(&w, str + i, sizeof(w)); + n = wcrtomb(dst + j, w, &mbs); if (n == (size_t)-1) - HANDLE_MBR_ERROR(n, mbs, dst[j], str[i]); + HANDLE_MBR_ERROR(n, mbs, dst[j], w); j += n; if (buflen < j + MB_CUR_MAX) { if (id != (iconv_t)-1) { @@ -297,7 +308,7 @@ default_int2char(SCR *sp, const CHAR_T * } } - n = wcrtomb(dst+j, L'\0', &mbs); + n = wcrtomb(dst + j, L'\0', &mbs); j += n - 1; /* don't count NUL at the end */ *tolen = j;