REVIEWED: sinfl, fix #3349
This commit is contained in:
parent
1aad6a2fc0
commit
c4fb6c8517
1 changed files with 28 additions and 10 deletions
38
src/external/sinfl.h
vendored
38
src/external/sinfl.h
vendored
|
@ -5,6 +5,8 @@ which implements the Deflate (RFC 1951) compressed data format specification sta
|
||||||
It is mainly tuned to get as much speed and compression ratio from as little code
|
It is mainly tuned to get as much speed and compression ratio from as little code
|
||||||
as needed to keep the implementation as concise as possible.
|
as needed to keep the implementation as concise as possible.
|
||||||
|
|
||||||
|
@raysan5: this file has been reviewed as per https://github.com/raysan5/raylib/issues/3349
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
- Portable single header and source file duo written in ANSI C (ISO C90)
|
- Portable single header and source file duo written in ANSI C (ISO C90)
|
||||||
- Dual license with either MIT or public domain
|
- Dual license with either MIT or public domain
|
||||||
|
@ -122,6 +124,7 @@ extern "C" {
|
||||||
|
|
||||||
struct sinfl {
|
struct sinfl {
|
||||||
const unsigned char *bitptr;
|
const unsigned char *bitptr;
|
||||||
|
const unsigned char *bitend; // @raysan5, added
|
||||||
unsigned long long bitbuf;
|
unsigned long long bitbuf;
|
||||||
int bitcnt;
|
int bitcnt;
|
||||||
|
|
||||||
|
@ -177,17 +180,23 @@ sinfl_bsr(unsigned n) {
|
||||||
return 31 - __builtin_clz(n);
|
return 31 - __builtin_clz(n);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
static unsigned long long
|
// @raysan5, commented
|
||||||
sinfl_read64(const void *p) {
|
//static unsigned long long
|
||||||
unsigned long long n;
|
//sinfl_read64(const void *p) {
|
||||||
memcpy(&n, p, 8);
|
// unsigned long long n;
|
||||||
return n;
|
// memcpy(&n, p, 8);
|
||||||
}
|
// return n;
|
||||||
|
//}
|
||||||
static void
|
static void
|
||||||
sinfl_copy64(unsigned char **dst, unsigned char **src) {
|
sinfl_copy64(unsigned char **dst, unsigned char **src) {
|
||||||
unsigned long long n;
|
// @raysan5, reviewed
|
||||||
memcpy(&n, *src, 8);
|
//----------------------------
|
||||||
memcpy(*dst, &n, 8);
|
//unsigned long long n;
|
||||||
|
//memcpy(&n, *src, 8);
|
||||||
|
//memcpy(*dst, &n, 8);
|
||||||
|
memcpy(*dst, *src, 8);
|
||||||
|
//----------------------------
|
||||||
|
|
||||||
*dst += 8, *src += 8;
|
*dst += 8, *src += 8;
|
||||||
}
|
}
|
||||||
static unsigned char*
|
static unsigned char*
|
||||||
|
@ -210,7 +219,14 @@ sinfl_copy128(unsigned char **dst, unsigned char **src) {
|
||||||
#endif
|
#endif
|
||||||
static void
|
static void
|
||||||
sinfl_refill(struct sinfl *s) {
|
sinfl_refill(struct sinfl *s) {
|
||||||
s->bitbuf |= sinfl_read64(s->bitptr) << s->bitcnt;
|
// @raysan5, reviewed
|
||||||
|
//---------------------------------------------------
|
||||||
|
//s->bitbuf |= sinfl_read64(s->bitptr) << s->bitcnt;
|
||||||
|
unsigned long long n = 0;
|
||||||
|
memcpy(&n, p, s->bitptr + 8 < s->bitend ? 8 : s->bitend - s->bitptr);
|
||||||
|
s->bitbuf |= n << s->bitcnt;
|
||||||
|
//---------------------------------------------------
|
||||||
|
|
||||||
s->bitptr += (63 - s->bitcnt) >> 3;
|
s->bitptr += (63 - s->bitcnt) >> 3;
|
||||||
s->bitcnt |= 56; /* bitcount in range [56,63] */
|
s->bitcnt |= 56; /* bitcount in range [56,63] */
|
||||||
}
|
}
|
||||||
|
@ -384,6 +400,8 @@ sinfl_decompress(unsigned char *out, int cap, const unsigned char *in, int size)
|
||||||
int last = 0;
|
int last = 0;
|
||||||
|
|
||||||
s.bitptr = in;
|
s.bitptr = in;
|
||||||
|
s.bitend = e; // @raysan5, added
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case hdr: {
|
case hdr: {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue