Skip to content

Commit 042da83

Browse files
committed
variant_byte_number: Handle unusual byte ordering
Instead of refusing to compile, it is easy to handle this case.
1 parent 83b95f2 commit 042da83

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

inline.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,8 +2055,20 @@ Perl_variant_byte_number(PERL_UINTMAX_T word)
20552055

20562056
return (unsigned int) word;
20572057

2058-
# else
2059-
# error Unexpected byte order
2058+
#else /* Unhandled byte-order; the compiler knows which comes first */
2059+
2060+
const U8 * bytes = (U8 *) &word;
2061+
for (unsigned int i = 0; i < sizeof(word); i++) {
2062+
if (bytes[i]) {
2063+
return i;
2064+
}
2065+
}
2066+
2067+
assert(0);
2068+
2069+
/* If all else fails, it's better to return something than just random */
2070+
return 0;
2071+
20602072
# endif
20612073

20622074
}

0 commit comments

Comments
 (0)