From a4ca971e26a4e58c408bf03cce8858b21a521767 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Fri, 14 Nov 2014 04:23:09 +0000 Subject: 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. --- usr.bin/mandoc/preconv.c | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) (limited to 'usr.bin') 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 * Copyright (c) 2014 Ingo Schwarze @@ -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 -- cgit v1.2.3