From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: Remove needless and harmful byte swapping on big endian
Date: Thu, 13 Nov 2014 23:24:04 -0500 (EST) [thread overview]
Message-ID: <201411140424.sAE4O4xZ020151@krisdoz.my.domain> (raw)
Log Message:
-----------
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.
While here, sync with OpenBSD by removing some trailing whitespace.
Modified Files:
--------------
mdocml:
preconv.c
Revision Data
-------------
Index: preconv.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/preconv.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -Lpreconv.c -Lpreconv.c -u -p -r1.11 -r1.12
--- preconv.c
+++ preconv.c
@@ -29,8 +29,7 @@ preconv_encode(struct buf *ib, size_t *i
int *filenc)
{
size_t i;
- const long one = 1L;
- int state, be;
+ int state;
unsigned int accum;
unsigned char cu;
@@ -39,12 +38,6 @@ preconv_encode(struct buf *ib, size_t *i
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];
@@ -66,19 +59,6 @@ preconv_encode(struct buf *ib, size_t *i
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
@@ -93,7 +73,7 @@ preconv_encode(struct buf *ib, size_t *i
* UTF-8 bitmask, calculate the expected UTF-8
* state from it.
*/
- for (state = 0; state < 7; state++)
+ for (state = 0; state < 7; state++)
if ( ! (cu & (1 << (7 - state))))
break;
@@ -158,7 +138,7 @@ preconv_cue(const struct buf *b, size_t
/* Check if we have the correct header/trailer. */
- if ((sz = (size_t)(eoln - ln)) < 10 ||
+ if ((sz = (size_t)(eoln - ln)) < 10 ||
memcmp(ln, ".\\\" -*-", 7) || memcmp(eoln - 3, "-*-", 3))
return(MPARSE_UTF8 | MPARSE_LATIN1);
@@ -189,7 +169,7 @@ preconv_cue(const struct buf *b, size_t
sz -= phsz;
ln += phsz;
continue;
- }
+ }
sz -= 7;
ln += 7;
--
To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv
reply other threads:[~2014-11-14 4:24 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201411140424.sAE4O4xZ020151@krisdoz.my.domain \
--to=schwarze@mdocml.bsd.lv \
--cc=source@mdocml.bsd.lv \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).