Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/bsd/nvi/dist/common handle unaligned accesses



details:   https://anonhg.NetBSD.org/src/rev/9281d88c48c9
branches:  trunk
changeset: 792563:9281d88c48c9
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Jan 07 21:46:47 2014 +0000

description:
handle unaligned accesses

diffstat:

 external/bsd/nvi/dist/common/conv.c |  35 +++++++++++++++++++++++------------
 1 files changed, 23 insertions(+), 12 deletions(-)

diffs (79 lines):

diff -r c8a3ba59840a -r 9281d88c48c9 external/bsd/nvi/dist/common/conv.c
--- a/external/bsd/nvi/dist/common/conv.c       Tue Jan 07 20:25:24 2014 +0000
+++ b/external/bsd/nvi/dist/common/conv.c       Tue Jan 07 21:46:47 2014 +0000
@@ -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 @@
     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 @@
 #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 @@
     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 @@
 #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 @@
        }
     }
 
-    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;
 



Home | Main Index | Thread Index | Old Index