瀏覽代碼

REVIEWED: sinfl, fix #3349

pull/3452/head
Ray 1 年之前
父節點
當前提交
c4fb6c8517
共有 1 個檔案被更改,包括 28 行新增10 行删除
  1. +28
    -10
      src/external/sinfl.h

+ 28
- 10
src/external/sinfl.h 查看文件

@ -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
sinfl_read64(const void *p) {
unsigned long long n;
memcpy(&n, p, 8);
return n;
}
// @raysan5, commented
//static unsigned long long
//sinfl_read64(const void *p) {
// unsigned long long 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;
memcpy(&n, *src, 8);
memcpy(*dst, &n, 8);
// @raysan5, reviewed
//----------------------------
//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…
取消
儲存