[M67 Dev][EFL] Fix crashes at webview launch
[platform/framework/web/chromium-efl.git] / third_party / libjpeg / google.shift-negative-values.patch
1 diff --git a/third_party/libjpeg/jdhuff.c b/third_party/libjpeg/jdhuff.c
2 index b5ba39f736a7..13dd0f93dc99 100644
3 --- a/third_party/libjpeg/jdhuff.c
4 +++ b/third_party/libjpeg/jdhuff.c
5 @@ -435,26 +435,22 @@ jpeg_huff_decode (bitread_working_state * state,
6  
7  /*
8   * Figure F.12: extend sign bit.
9 - * On some machines, a shift and add will be faster than a table lookup.
10 + * On some machines, a shift and sub will be faster than a table lookup.
11   */
12  
13  #ifdef AVOID_TABLES
14  
15 -#define HUFF_EXTEND(x,s)  ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x))
16 +#define BIT_MASK(nbits)   ((1<<(nbits))-1)
17 +#define HUFF_EXTEND(x,s)  ((x) < (1<<((s)-1)) ? (x) - ((1<<(s))-1) : (x))
18  
19  #else
20  
21 -#define HUFF_EXTEND(x,s)  ((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
22 -
23 -static const int extend_test[16] =   /* entry n is 2**(n-1) */
24 -  { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
25 -    0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 };
26 +#define BIT_MASK(nbits)   bmask[nbits]
27 +#define HUFF_EXTEND(x,s)  ((x) <= bmask[(s) - 1] ? (x) - bmask[s] : (x))
28  
29 -static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
30 -  { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1,
31 -    ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1,
32 -    ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1,
33 -    ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };
34 +static const int bmask[16] =  /* bmask[n] is mask for n rightmost bits */
35 +  { 0, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F, 0x00FF,
36 +    0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF };
37  
38  #endif /* AVOID_TABLES */
39  
40 diff --git a/third_party/libjpeg/jdphuff.c b/third_party/libjpeg/jdphuff.c
41 index 22678099451a..32df3af76707 100644
42 --- a/third_party/libjpeg/jdphuff.c
43 +++ b/third_party/libjpeg/jdphuff.c
44 @@ -195,26 +195,22 @@ start_pass_phuff_decoder (j_decompress_ptr cinfo)
45  
46  /*
47   * Figure F.12: extend sign bit.
48 - * On some machines, a shift and add will be faster than a table lookup.
49 + * On some machines, a shift and sub will be faster than a table lookup.
50   */
51  
52  #ifdef AVOID_TABLES
53  
54 -#define HUFF_EXTEND(x,s)  ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x))
55 +#define BIT_MASK(nbits)   ((1<<(nbits))-1)
56 +#define HUFF_EXTEND(x,s)  ((x) < (1<<((s)-1)) ? (x) - ((1<<(s))-1) : (x))
57  
58  #else
59  
60 -#define HUFF_EXTEND(x,s)  ((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
61 +#define BIT_MASK(nbits)   bmask[nbits]
62 +#define HUFF_EXTEND(x,s)  ((x) <= bmask[(s) - 1] ? (x) - bmask[s] : (x))
63  
64 -static const int extend_test[16] =   /* entry n is 2**(n-1) */
65 -  { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
66 -    0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 };
67 -
68 -static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
69 -  { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1,
70 -    ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1,
71 -    ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1,
72 -    ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };
73 +static const int bmask[16] =  /* bmask[n] is mask for n rightmost bits */
74 +  { 0, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F, 0x00FF,
75 +    0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF };
76  
77  #endif /* AVOID_TABLES */
78