Skip to content

Commit 5afd655

Browse files
authored
changed bs->end meaning (#110)
Signed-off-by: Kwang Pyo Choi <kp5.choi@samsung.com>
1 parent ad8e6f8 commit 5afd655

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/oapv_bs.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void oapv_bsw_init(oapv_bs_t *bs, u8 *buf, int size, oapv_bs_fn_flush_t fn_flush
5858
bs->size = size;
5959
bs->beg = buf;
6060
bs->cur = buf;
61-
bs->end = buf + size - 1;
61+
bs->end = buf + size;
6262
bs->code = 0;
6363
bs->leftbits = 32;
6464
bs->fn_flush = (fn_flush == NULL ? bsw_flush : fn_flush);
@@ -73,7 +73,7 @@ void oapv_bsw_deinit(oapv_bs_t *bs)
7373

7474
void *oapv_bsw_sink(oapv_bs_t *bs)
7575
{
76-
oapv_assert_rv(bs->cur + BSW_GET_SINK_BYTE(bs) <= bs->end, NULL);
76+
oapv_assert_rv(bs->cur + BSW_GET_SINK_BYTE(bs) < bs->end, NULL);
7777
bs->fn_flush(bs, 0);
7878
bs->code = 0;
7979
bs->leftbits = 32;
@@ -108,7 +108,7 @@ int oapv_bsw_write1(oapv_bs_t *bs, int val)
108108
bs->code |= ((val & 0x1) << bs->leftbits);
109109

110110
if(bs->leftbits == 0) {
111-
oapv_assert_rv(bs->cur <= bs->end, -1);
111+
oapv_assert_rv(bs->cur < bs->end, -1);
112112
bs->fn_flush(bs, 0);
113113

114114
bs->code = 0;
@@ -137,7 +137,7 @@ int oapv_bsw_write(oapv_bs_t *bs, u32 val, int len) /* len(1 ~ 32) */
137137
bs->leftbits -= len;
138138
}
139139
else {
140-
oapv_assert_rv(bs->cur + 4 <= bs->end, -1);
140+
oapv_assert_rv(bs->cur + 4 < bs->end, -1);
141141

142142
bs->leftbits = 0;
143143
bs->fn_flush(bs, 0);
@@ -185,7 +185,7 @@ static int bsr_flush(oapv_bs_t *bs, int byte)
185185

186186
oapv_assert(byte);
187187

188-
remained = (int)(bs->end - bs->cur) + 1;
188+
remained = (int)(bs->end - bs->cur);
189189
if(byte > remained)
190190
byte = remained;
191191

@@ -211,7 +211,7 @@ void oapv_bsr_init(oapv_bs_t *bs, u8 *buf, u32 size, oapv_bs_fn_flush_t fn_flush
211211
bs->size = size;
212212
bs->cur = buf;
213213
bs->beg = buf;
214-
bs->end = buf + size - 1;
214+
bs->end = buf + size;
215215
bs->code = 0;
216216
bs->leftbits = 0;
217217
bs->fn_flush = (fn_flush == NULL) ? bsr_flush : fn_flush;
@@ -308,7 +308,7 @@ u32 oapv_bsr_peek(oapv_bs_t *bs, int size)
308308
larger than current bs->leftbits.
309309
In this case, we should read one more byte, but we could not store
310310
the read byte. */
311-
if(bs->cur <= bs->end) {
311+
if(bs->cur < bs->end) {
312312
code |= *(bs->cur) >> (8 - size);
313313
}
314314
}
@@ -317,7 +317,7 @@ u32 oapv_bsr_peek(oapv_bs_t *bs, int size)
317317

318318
void *oapv_bsr_sink(oapv_bs_t *bs)
319319
{
320-
oapv_assert_rv(bs->cur + BSW_GET_SINK_BYTE(bs) <= bs->end, NULL);
320+
oapv_assert_rv(bs->cur + BSW_GET_SINK_BYTE(bs) < bs->end, NULL);
321321
oapv_assert_rv((bs->leftbits & 7) == 0, NULL);
322322
bs->cur = bs->cur - (bs->leftbits >> 3);
323323
bs->code = 0;

src/oapv_bs.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,18 @@ should set zero in that case. */
101101
#endif
102102

103103
/*! Is end of bitstream ? */
104-
#define BSR_IS_EOB(bs) (((bs)->cur > (bs)->end && (bs)->leftbits==0)? 1: 0)
104+
#define BSR_IS_EOB(bs) (((bs)->cur >= (bs)->end && (bs)->leftbits==0)? 1: 0)
105105

106106
/*! Is bitstream byte aligned? */
107107
#define BSR_IS_BYTE_ALIGN(bs) ((((bs)->leftbits & 0x7) == 0)? 1: 0)
108108

109109
/*! Is last byte of bitsteam? */
110110
#define BSR_IS_LAST_BYTE(bs) \
111-
(((bs)->cur > (bs)->end && bs->leftbits > 0 && (bs)->leftbits <= 8)? 1: 0)
111+
(((bs)->cur >= (bs)->end && bs->leftbits > 0 && (bs)->leftbits <= 8)? 1: 0)
112112

113113
/* get left byte count in BS */
114114
#define BSR_GET_LEFT_BYTE(bs) \
115-
((int)((bs)->end - (bs)->cur) + 1 + ((bs)->leftbits >> 3))
115+
((int)((bs)->end - (bs)->cur) + ((bs)->leftbits >> 3))
116116
/* get number of byte consumed */
117117
#define BSR_GET_READ_BYTE(bs) \
118118
((int)((bs)->cur - (bs)->beg) - ((bs)->leftbits >> 3))

src/oapv_vlc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,7 @@ int oapvd_vlc_tile_header(oapv_bs_t *bs, oapvd_ctx_t *ctx, oapv_th_t *th)
13971397

13981398
int oapvd_vlc_tile_dummy_data(oapv_bs_t *bs)
13991399
{
1400-
while(bs->cur <= bs->end) {
1400+
while(bs->cur < bs->end) {
14011401
oapv_bsr_read(bs, 8);
14021402
}
14031403
return OAPV_OK;

0 commit comments

Comments
 (0)