Skip to content

Commit

Permalink
Some variables' type changed from int to size_t. (closing fukuchi#89
Browse files Browse the repository at this point in the history
…and fukuchi#102)
  • Loading branch information
fukuchi committed Oct 2, 2017
1 parent 9662324 commit 63eca20
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
- Error messages improved.
* tests/{common.h datachunk.h, decoder.h, rscode.h, rsecc_decoder.h}:
- Reserved macro names are replaced.
* bitstream.[ch]:
- Some variables' type changed from int to size_t. (closing #89 and
#102)

2017.09.29 Kentaro Fukuchi <[email protected]>
[4.0]
Expand Down
23 changes: 11 additions & 12 deletions bitstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ BitStream *BitStream_new(void)
}

#ifdef WITH_TESTS
BitStream *BitStream_newWithBits(int size, unsigned char *bits)
BitStream *BitStream_newWithBits(size_t size, unsigned char *bits)
{
BitStream *bstream;

if(size < 0) return NULL;
if(size == 0) return BitStream_new();

bstream = (BitStream *)malloc(sizeof(BitStream));
Expand Down Expand Up @@ -88,10 +87,10 @@ static int BitStream_expand(BitStream *bstream)
return 0;
}

static void BitStream_writeNum(unsigned char *dest, int bits, unsigned int num)
static void BitStream_writeNum(unsigned char *dest, size_t bits, unsigned int num)
{
unsigned int mask;
int i;
size_t i;
unsigned char *p;

p = dest;
Expand All @@ -107,10 +106,10 @@ static void BitStream_writeNum(unsigned char *dest, int bits, unsigned int num)
}
}

static void BitStream_writeBytes(unsigned char *dest, int size, unsigned char *data)
static void BitStream_writeBytes(unsigned char *dest, size_t size, unsigned char *data)
{
unsigned char mask;
int i, j;
size_t i, j;
unsigned char *p;

p = dest;
Expand Down Expand Up @@ -150,7 +149,7 @@ int BitStream_append(BitStream *bstream, BitStream *arg)
return 0;
}

int BitStream_appendNum(BitStream *bstream, int bits, unsigned int num)
int BitStream_appendNum(BitStream *bstream, size_t bits, unsigned int num)
{
int ret;

Expand All @@ -166,7 +165,7 @@ int BitStream_appendNum(BitStream *bstream, int bits, unsigned int num)
return 0;
}

int BitStream_appendBytes(BitStream *bstream, int size, unsigned char *data)
int BitStream_appendBytes(BitStream *bstream, size_t size, unsigned char *data)
{
int ret;

Expand All @@ -184,7 +183,7 @@ int BitStream_appendBytes(BitStream *bstream, int size, unsigned char *data)

unsigned char *BitStream_toByte(BitStream *bstream)
{
int i, j, size, bytes, oddbits;
size_t i, j, size, bytes, oddbits;
unsigned char *data, v;
unsigned char *p;

Expand All @@ -203,7 +202,7 @@ unsigned char *BitStream_toByte(BitStream *bstream)
for(i = 0; i < bytes; i++) {
v = 0;
for(j = 0; j < 8; j++) {
v = v << 1;
v = (unsigned char)(v << 1);
v |= *p;
p++;
}
Expand All @@ -213,11 +212,11 @@ unsigned char *BitStream_toByte(BitStream *bstream)
if(oddbits > 0) {
v = 0;
for(j = 0; j < oddbits; j++) {
v = v << 1;
v = (unsigned char)(v << 1);
v |= *p;
p++;
}
data[bytes] = v << (8 - oddbits);
data[bytes] = (unsigned char)(v << (8 - oddbits));
}

return data;
Expand Down
10 changes: 5 additions & 5 deletions bitstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@
#define BITSTREAM_H

typedef struct {
int length;
int datasize;
size_t length;
size_t datasize;
unsigned char *data;
} BitStream;

extern BitStream *BitStream_new(void);
#ifdef WITH_TESTS
extern BitStream *BitStream_newWithBits(int size, unsigned char *bits);
extern BitStream *BitStream_newWithBits(size_t size, unsigned char *bits);
#endif
extern int BitStream_append(BitStream *bstream, BitStream *arg);
extern int BitStream_appendNum(BitStream *bstream, int bits, unsigned int num);
extern int BitStream_appendBytes(BitStream *bstream, int size, unsigned char *data);
extern int BitStream_appendNum(BitStream *bstream, size_t bits, unsigned int num);
extern int BitStream_appendBytes(BitStream *bstream, size_t size, unsigned char *data);
#define BitStream_size(__bstream__) (__bstream__->length)
#define BitStream_reset(__bstream__) (__bstream__->length = 0)
extern unsigned char *BitStream_toByte(BitStream *bstream);
Expand Down

0 comments on commit 63eca20

Please sign in to comment.