Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
Heatshrink
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Grant Kim
Heatshrink
Commits
b5d14090
Commit
b5d14090
authored
9 years ago
by
Vadim Vygonets
Committed by
Scott Vokes
9 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Change get_bits() to uint16_t
It's only called with count <= 8.
parent
e3d06aed
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
heatshrink_decoder.c
+12
-12
12 additions, 12 deletions
heatshrink_decoder.c
with
12 additions
and
12 deletions
heatshrink_decoder.c
+
12
−
12
View file @
b5d14090
...
...
@@ -43,10 +43,10 @@ typedef struct {
size_t
*
output_size
;
/* bytes pushed to buffer, so far */
}
output_info
;
#define NO_BITS ((uint
32
_t)-1)
#define NO_BITS ((uint
16
_t)-1)
/* Forward references. */
static
uint
32
_t
get_bits
(
heatshrink_decoder
*
hsd
,
uint8_t
count
);
static
uint
16
_t
get_bits
(
heatshrink_decoder
*
hsd
,
uint8_t
count
);
static
void
push_byte
(
heatshrink_decoder
*
hsd
,
output_info
*
oi
,
uint8_t
byte
);
#if HEATSHRINK_DYNAMIC_ALLOC
...
...
@@ -199,7 +199,7 @@ HSD_poll_res heatshrink_decoder_poll(heatshrink_decoder *hsd,
}
static
HSD_state
st_input_available
(
heatshrink_decoder
*
hsd
)
{
uint
32
_t
bits
=
get_bits
(
hsd
,
1
);
// get tag bit
uint
16
_t
bits
=
get_bits
(
hsd
,
1
);
// get tag bit
if
(
bits
)
{
return
HSDS_YIELD_LITERAL
;
}
else
if
(
HEATSHRINK_DECODER_WINDOW_BITS
(
hsd
)
>
8
)
{
...
...
@@ -216,7 +216,7 @@ static HSD_state st_yield_literal(heatshrink_decoder *hsd,
* to the window buffer. (Note that the repetition can include
* itself.)*/
if
(
*
oi
->
output_size
<
oi
->
buf_size
)
{
uint
32
_t
byte
=
get_bits
(
hsd
,
8
);
uint
16
_t
byte
=
get_bits
(
hsd
,
8
);
if
(
byte
==
NO_BITS
)
{
return
HSDS_YIELD_LITERAL
;
}
/* out of input */
uint8_t
*
buf
=
&
hsd
->
buffers
[
HEATSHRINK_DECODER_INPUT_BUFFER_SIZE
(
hsd
)];
uint16_t
mask
=
(
1
<<
HEATSHRINK_DECODER_WINDOW_BITS
(
hsd
))
-
1
;
...
...
@@ -233,7 +233,7 @@ static HSD_state st_yield_literal(heatshrink_decoder *hsd,
static
HSD_state
st_backref_index_msb
(
heatshrink_decoder
*
hsd
)
{
uint8_t
bit_ct
=
BACKREF_INDEX_BITS
(
hsd
);
ASSERT
(
bit_ct
>
8
);
uint
32
_t
bits
=
get_bits
(
hsd
,
bit_ct
-
8
);
uint
16
_t
bits
=
get_bits
(
hsd
,
bit_ct
-
8
);
LOG
(
"-- backref index (msb), got 0x%04x (+1)
\n
"
,
bits
);
if
(
bits
==
NO_BITS
)
{
return
HSDS_BACKREF_INDEX_MSB
;
}
hsd
->
output_index
=
bits
<<
8
;
...
...
@@ -242,7 +242,7 @@ static HSD_state st_backref_index_msb(heatshrink_decoder *hsd) {
static
HSD_state
st_backref_index_lsb
(
heatshrink_decoder
*
hsd
)
{
uint8_t
bit_ct
=
BACKREF_INDEX_BITS
(
hsd
);
uint
32
_t
bits
=
get_bits
(
hsd
,
bit_ct
<
8
?
bit_ct
:
8
);
uint
16
_t
bits
=
get_bits
(
hsd
,
bit_ct
<
8
?
bit_ct
:
8
);
LOG
(
"-- backref index (lsb), got 0x%04x (+1)
\n
"
,
bits
);
if
(
bits
==
NO_BITS
)
{
return
HSDS_BACKREF_INDEX_LSB
;
}
hsd
->
output_index
|=
bits
;
...
...
@@ -255,7 +255,7 @@ static HSD_state st_backref_index_lsb(heatshrink_decoder *hsd) {
static
HSD_state
st_backref_count_msb
(
heatshrink_decoder
*
hsd
)
{
uint8_t
br_bit_ct
=
BACKREF_COUNT_BITS
(
hsd
);
ASSERT
(
br_bit_ct
>
8
);
uint
32
_t
bits
=
get_bits
(
hsd
,
br_bit_ct
-
8
);
uint
16
_t
bits
=
get_bits
(
hsd
,
br_bit_ct
-
8
);
LOG
(
"-- backref count (msb), got 0x%04x (+1)
\n
"
,
bits
);
if
(
bits
==
NO_BITS
)
{
return
HSDS_BACKREF_COUNT_MSB
;
}
hsd
->
output_count
=
bits
<<
8
;
...
...
@@ -264,7 +264,7 @@ static HSD_state st_backref_count_msb(heatshrink_decoder *hsd) {
static
HSD_state
st_backref_count_lsb
(
heatshrink_decoder
*
hsd
)
{
uint8_t
br_bit_ct
=
BACKREF_COUNT_BITS
(
hsd
);
uint
32
_t
bits
=
get_bits
(
hsd
,
br_bit_ct
<
8
?
br_bit_ct
:
8
);
uint
16
_t
bits
=
get_bits
(
hsd
,
br_bit_ct
<
8
?
br_bit_ct
:
8
);
LOG
(
"-- backref count (lsb), got 0x%04x (+1)
\n
"
,
bits
);
if
(
bits
==
NO_BITS
)
{
return
HSDS_BACKREF_COUNT_LSB
;
}
hsd
->
output_count
|=
bits
;
...
...
@@ -303,10 +303,10 @@ static HSD_state st_check_for_input(heatshrink_decoder *hsd) {
}
/* Get the next COUNT bits from the input buffer, saving incremental progress.
* Returns NO_BITS on end of input, or if more than
3
1 bits are requested. */
static
uint
32
_t
get_bits
(
heatshrink_decoder
*
hsd
,
uint8_t
count
)
{
* Returns NO_BITS on end of input, or if more than 1
5
bits are requested. */
static
uint
16
_t
get_bits
(
heatshrink_decoder
*
hsd
,
uint8_t
count
)
{
int
i
=
0
;
if
(
count
>
3
1
)
{
return
NO_BITS
;
}
if
(
count
>
1
5
)
{
return
NO_BITS
;
}
LOG
(
"-- popping %u bit(s)
\n
"
,
count
);
/* If we aren't able to get COUNT bits, suspend immediately, because we
...
...
@@ -346,7 +346,7 @@ static uint32_t get_bits(heatshrink_decoder *hsd, uint8_t count) {
hsd
->
bit_index
>>=
1
;
}
uint
32
_t
res
=
0
;
uint
16
_t
res
=
0
;
res
=
hsd
->
bit_accumulator
;
hsd
->
bit_accumulator
=
0x00000000
;
if
(
count
>
1
)
{
LOG
(
" -- accumulated %08x
\n
"
,
res
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment