Skip to content

Commit

Permalink
Fix bad usage of uint8_fast_t in Back_Scan_Utf8_Char
Browse files Browse the repository at this point in the history
The purpose of the `uint_fast8_t` type in `<stdint.h>` is to allow
you to express that you only need 8 bits worth of storage, but the
compiler is allowed to decide that the fastest way it can manipulate
small quantities on the platform is by using a size larger than 8-bits.

https://stackoverflow.com/q/35055042/

Hence it may not be the same size as an `unsigned char`, and should
not be used to do things like address into strings (for example).

A mistake in the usage of uint_fast8_t that meant to use it to hold a
trailing byte count was actually using it on the wrong line, which
was making it try to point at characters.  This leads to crashes on
platforms where sizeof(uint8_fast_t) != sizeof(unsigned char)...
for example, OpenBSD.

Fix is to use the uint_fast8_t on the right line.
  • Loading branch information
hostilefork committed Mar 23, 2019
1 parent f0c2bf4 commit e74dc7d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/include/sys-char.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,12 @@ inline static const REBYTE *Back_Scan_UTF8_Char(
){
*out = 0;

const uint_fast8_t *source = bp;
REBCNT trail = trailingBytesForUTF8[*source];
const REBYTE *source = bp;
uint_fast8_t trail = trailingBytesForUTF8[*source];

// Check that we have enough valid source bytes:
if (size) {
if (trail + 1 > *size)
if (cast(uint_fast8_t, trail + 1) > *size)
return nullptr;
}
else if (trail != 0) {
Expand Down

0 comments on commit e74dc7d

Please sign in to comment.