Skip to content

Commit

Permalink
parser_priv: Change type of fontdata_{size,used} to size_t
Browse files Browse the repository at this point in the history
size_t is a more sensible type for as it is unsigned and accurately
represents the theoretical limits of object size. int may be larger or
smaller than size_t, which both would lead to problems and potential UB
with signed overflow.
There was no usage of negative values as error flags or similar and
those two fields are not part of the public API, so this change should
be safe.

To stay consistent, also adjust types of related variables in functions.
  • Loading branch information
TheOneric authored and astiob committed Oct 26, 2020
1 parent 241e613 commit 910211f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions libass/ass.c
Expand Up @@ -807,7 +807,7 @@ static int process_events_line(ASS_Track *track, char *str)
}

static unsigned char *decode_chars(const unsigned char *src,
unsigned char *dst, int cnt_in)
unsigned char *dst, size_t cnt_in)
{
uint32_t value = 0;
for (int i = 0; i < cnt_in; i++)
Expand All @@ -825,9 +825,9 @@ static int decode_font(ASS_Track *track)
{
unsigned char *p;
unsigned char *q;
int i;
int size; // original size
int dsize; // decoded size
size_t i;
size_t size; // original size
size_t dsize; // decoded size
unsigned char *buf = 0;

ass_msg(track->library, MSGL_V, "Font: %d bytes encoded data",
Expand Down Expand Up @@ -871,7 +871,7 @@ static int decode_font(ASS_Track *track)

static int process_fonts_line(ASS_Track *track, char *str)
{
int len;
size_t len;

if (!strncmp(str, "fontname:", 9)) {
char *p = str + 9;
Expand Down
4 changes: 2 additions & 2 deletions libass/ass_priv.h
Expand Up @@ -50,8 +50,8 @@ struct parser_priv {
ParserState state;
char *fontname;
char *fontdata;
int fontdata_size;
int fontdata_used;
size_t fontdata_size;
size_t fontdata_used;

// contains bitmap of ReadOrder IDs of all read events
uint32_t *read_order_bitmap;
Expand Down

0 comments on commit 910211f

Please sign in to comment.