summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2014-11-14 04:23:09 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2014-11-14 04:23:09 +0000
commita4ca971e26a4e58c408bf03cce8858b21a521767 (patch)
tree12e5367cd4b4eb3621a8f1b2bb604b21a0f1b800 /usr.bin
parentc189a2bcaf4b8a56cb6b97f82398ad396d1011e8 (diff)
Remove needless and harmful byte swapping on big endian architectures.
Problem found and patch provided by Martin Natano at bitrig, thanks! Tested on macppc by natano@ and on i386, amd64, and sparc64 myself.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/mandoc/preconv.c24
1 files changed, 2 insertions, 22 deletions
diff --git a/usr.bin/mandoc/preconv.c b/usr.bin/mandoc/preconv.c
index aa709191c88..cb3d355ca4a 100644
--- a/usr.bin/mandoc/preconv.c
+++ b/usr.bin/mandoc/preconv.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: preconv.c,v 1.2 2014/11/01 04:07:25 schwarze Exp $ */
+/* $OpenBSD: preconv.c,v 1.3 2014/11/14 04:23:08 schwarze Exp $ */
/*
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -28,8 +28,7 @@ preconv_encode(struct buf *ib, size_t *ii, struct buf *ob, size_t *oi,
int *filenc)
{
size_t i;
- const long one = 1L;
- int state, be;
+ int state;
unsigned int accum;
unsigned char cu;
@@ -38,12 +37,6 @@ preconv_encode(struct buf *ib, size_t *ii, struct buf *ob, size_t *oi,
state = 0;
accum = 0U;
- be = 0;
-
- /* Quick test for big-endian value. */
-
- if ( ! (*((const char *)(&one))))
- be = 1;
for (i = *ii; i < ib->sz; i++) {
cu = ib->buf[i];
@@ -65,19 +58,6 @@ preconv_encode(struct buf *ib, size_t *ii, struct buf *ob, size_t *oi,
if (state)
continue;
- /*
- * Accum is held in little-endian order as
- * stipulated by the UTF-8 sequence coding. We
- * need to convert to a native big-endian if our
- * architecture requires it.
- */
-
- if (be)
- accum = (accum >> 24) |
- ((accum << 8) & 0x00FF0000) |
- ((accum >> 8) & 0x0000FF00) |
- (accum << 24);
-
if (accum < 0x80)
ob->buf[(*oi)++] = accum;
else