Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed implicit casts from size_t to int. #2

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions src/blocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static void
S_process_line(cmark_parser *parser, const unsigned char *buffer,
size_t bytes);

static cmark_node* make_block(cmark_node_type tag, int start_line, int start_column)
static cmark_node* make_block(cmark_node_type tag, int start_line, size_t start_column)
{
cmark_node* e;

Expand Down Expand Up @@ -84,7 +84,7 @@ static cmark_node*
finalize(cmark_parser *parser, cmark_node* b);

// Returns true if line has only space characters, else false.
static bool is_blank(cmark_strbuf *s, int offset)
static bool is_blank(cmark_strbuf *s, size_t offset)
{
while (offset < s->size) {
switch (s->ptr[offset]) {
Expand Down Expand Up @@ -116,15 +116,15 @@ static inline bool accepts_lines(cmark_node_type block_type)
block_type == NODE_CODE_BLOCK);
}

static void add_line(cmark_node* node, cmark_chunk *ch, int offset)
static void add_line(cmark_node* node, cmark_chunk *ch, size_t offset)
{
assert(node->open);
cmark_strbuf_put(&node->string_content, ch->data + offset, ch->len - offset);
}

static void remove_trailing_blank_lines(cmark_strbuf *ln)
{
int i;
long i;

for (i = ln->size - 1; i >= 0; --i) {
unsigned char c = ln->ptr[i];
Expand Down Expand Up @@ -185,7 +185,7 @@ static cmark_node*
finalize(cmark_parser *parser, cmark_node* b)
{
int firstlinelen;
int pos;
size_t pos;
cmark_node* item;
cmark_node* subitem;
cmark_node* parent;
Expand Down Expand Up @@ -289,7 +289,7 @@ finalize(cmark_parser *parser, cmark_node* b)

// Add a cmark_node as child of another. Return pointer to child.
static cmark_node* add_child(cmark_parser *parser, cmark_node* parent,
cmark_node_type block_type, int start_column)
cmark_node_type block_type, size_t start_column)
{
assert(parent);

Expand Down Expand Up @@ -338,10 +338,10 @@ static void process_inlines(cmark_node* root, cmark_reference_map *refmap)
// Attempts to parse a list item marker (bullet or enumerated).
// On success, returns length of the marker, and populates
// data with the details. On failure, returns 0.
static int parse_list_marker(cmark_chunk *input, int pos, cmark_list **dataptr)
static size_t parse_list_marker(cmark_chunk *input, size_t pos, cmark_list **dataptr)
{
unsigned char c;
int startpos;
size_t startpos;
cmark_list *data;

startpos = pos;
Expand Down Expand Up @@ -495,7 +495,7 @@ S_parser_feed(cmark_parser *parser, const unsigned char *buffer, size_t len,

static void chop_trailing_hashtags(cmark_chunk *ch)
{
int n, orig_n;
long n, orig_n;

cmark_chunk_rtrim(ch);
orig_n = n = ch->len - 1;
Expand All @@ -515,17 +515,17 @@ static void
S_process_line(cmark_parser *parser, const unsigned char *buffer, size_t bytes)
{
cmark_node* last_matched_container;
int offset = 0;
int matched = 0;
int lev = 0;
int i;
size_t offset = 0;
size_t matched = 0;
size_t lev = 0;
size_t i;
cmark_list *data = NULL;
bool all_matched = true;
cmark_node* container;
cmark_node* cur = parser->current;
bool blank = false;
int first_nonspace;
int indent;
size_t first_nonspace;
size_t indent;
cmark_chunk input;

utf8proc_detab(parser->curline, buffer, bytes);
Expand Down Expand Up @@ -683,7 +683,7 @@ S_process_line(cmark_parser *parser, const unsigned char *buffer, size_t bytes)
offset = first_nonspace + matched;
container = add_child(parser, container, NODE_HEADER, offset + 1);

int hashpos = cmark_chunk_strchr(&input, '#', first_nonspace);
size_t hashpos = cmark_chunk_strchr(&input, '#', first_nonspace);
int level = 0;

while (peek_at(&input, hashpos) == '#') {
Expand Down
40 changes: 20 additions & 20 deletions src/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ unsigned char cmark_strbuf__oom[1];
#define MIN(x,y) ((x<y) ? x : y)
#endif

void cmark_strbuf_init(cmark_strbuf *buf, int initial_size)
void cmark_strbuf_init(cmark_strbuf *buf, size_t initial_size)
{
buf->asize = 0;
buf->size = 0;
Expand All @@ -33,10 +33,10 @@ void cmark_strbuf_init(cmark_strbuf *buf, int initial_size)
cmark_strbuf_grow(buf, initial_size);
}

int cmark_strbuf_try_grow(cmark_strbuf *buf, int target_size, bool mark_oom)
int cmark_strbuf_try_grow(cmark_strbuf *buf, size_t target_size, bool mark_oom)
{
unsigned char *new_ptr;
int new_size;
size_t new_size;

if (buf->ptr == cmark_strbuf__oom)
return -1;
Expand Down Expand Up @@ -79,7 +79,7 @@ int cmark_strbuf_try_grow(cmark_strbuf *buf, int target_size, bool mark_oom)
return 0;
}

int cmark_strbuf_grow(cmark_strbuf *buf, int target_size)
int cmark_strbuf_grow(cmark_strbuf *buf, size_t target_size)
{
return cmark_strbuf_try_grow(buf, target_size, true);
}
Expand Down Expand Up @@ -112,7 +112,7 @@ void cmark_strbuf_clear(cmark_strbuf *buf)
buf->ptr[0] = '\0';
}

int cmark_strbuf_set(cmark_strbuf *buf, const unsigned char *data, int len)
int cmark_strbuf_set(cmark_strbuf *buf, const unsigned char *data, size_t len)
{
if (len <= 0 || data == NULL) {
cmark_strbuf_clear(buf);
Expand Down Expand Up @@ -142,7 +142,7 @@ int cmark_strbuf_putc(cmark_strbuf *buf, int c)
return 0;
}

int cmark_strbuf_put(cmark_strbuf *buf, const unsigned char *data, int len)
int cmark_strbuf_put(cmark_strbuf *buf, const unsigned char *data, long len)
{
if (len <= 0)
return 0;
Expand All @@ -161,8 +161,8 @@ int cmark_strbuf_puts(cmark_strbuf *buf, const char *string)

int cmark_strbuf_vprintf(cmark_strbuf *buf, const char *format, va_list ap)
{
const int expected_size = buf->size + (strlen(format) * 2);
int len;
const size_t expected_size = buf->size + (strlen(format) * 2);
long len;

ENSURE_SIZE(buf, expected_size);

Expand All @@ -184,7 +184,7 @@ int cmark_strbuf_vprintf(cmark_strbuf *buf, const char *format, va_list ap)
return -1;
}

if (len + 1 <= buf->asize - buf->size) {
if ((size_t)(len + 1) <= buf->asize - buf->size) {
buf->size += len;
break;
}
Expand All @@ -207,9 +207,9 @@ int cmark_strbuf_printf(cmark_strbuf *buf, const char *format, ...)
return r;
}

void cmark_strbuf_copy_cstr(char *data, int datasize, const cmark_strbuf *buf)
void cmark_strbuf_copy_cstr(char *data, size_t datasize, const cmark_strbuf *buf)
{
int copylen;
size_t copylen;

assert(data && datasize && buf);

Expand Down Expand Up @@ -245,7 +245,7 @@ unsigned char *cmark_strbuf_detach(cmark_strbuf *buf)
return data;
}

void cmark_strbuf_attach(cmark_strbuf *buf, unsigned char *ptr, int asize)
void cmark_strbuf_attach(cmark_strbuf *buf, unsigned char *ptr, size_t asize)
{
cmark_strbuf_free(buf);

Expand All @@ -268,7 +268,7 @@ int cmark_strbuf_cmp(const cmark_strbuf *a, const cmark_strbuf *b)
(a->size < b->size) ? -1 : (a->size > b->size) ? 1 : 0;
}

int cmark_strbuf_strchr(const cmark_strbuf *buf, int c, int pos)
int cmark_strbuf_strchr(const cmark_strbuf *buf, int c, size_t pos)
{
const unsigned char *p = (unsigned char *)memchr(buf->ptr + pos, c, buf->size - pos);
if (!p)
Expand All @@ -277,9 +277,9 @@ int cmark_strbuf_strchr(const cmark_strbuf *buf, int c, int pos)
return (int)(p - (const unsigned char *)buf->ptr);
}

int cmark_strbuf_strrchr(const cmark_strbuf *buf, int c, int pos)
long cmark_strbuf_strrchr(const cmark_strbuf *buf, int c, size_t pos)
{
int i;
long i;

for (i = pos; i >= 0; i--) {
if (buf->ptr[i] == (unsigned char) c)
Expand All @@ -289,15 +289,15 @@ int cmark_strbuf_strrchr(const cmark_strbuf *buf, int c, int pos)
return -1;
}

void cmark_strbuf_truncate(cmark_strbuf *buf, int len)
void cmark_strbuf_truncate(cmark_strbuf *buf, size_t len)
{
if (len < buf->size) {
buf->size = len;
buf->ptr[buf->size] = '\0';
}
}

void cmark_strbuf_drop(cmark_strbuf *buf, int n)
void cmark_strbuf_drop(cmark_strbuf *buf, long n)
{
if (n > 0) {
buf->size = buf->size - n;
Expand Down Expand Up @@ -325,7 +325,7 @@ void cmark_strbuf_rtrim(cmark_strbuf *buf)

void cmark_strbuf_trim(cmark_strbuf *buf)
{
int i = 0;
size_t i = 0;

if (!buf->size)
return;
Expand All @@ -343,7 +343,7 @@ void cmark_strbuf_trim(cmark_strbuf *buf)
void cmark_strbuf_normalize_whitespace(cmark_strbuf *s)
{
bool last_char_was_space = false;
int r, w;
size_t r, w;

for (r = 0, w = 0; r < s->size; ++r) {
switch (s->ptr[r]) {
Expand All @@ -368,7 +368,7 @@ void cmark_strbuf_normalize_whitespace(cmark_strbuf *s)
// Destructively unescape a string: remove backslashes before punctuation chars.
extern void cmark_strbuf_unescape(cmark_strbuf *buf)
{
int r, w;
size_t r, w;

for (r = 0, w = 0; r < buf->size; ++r) {
if (buf->ptr[r] == '\\' && cmark_ispunct(buf->ptr[r + 1]))
Expand Down
24 changes: 12 additions & 12 deletions src/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extern "C" {

typedef struct {
unsigned char *ptr;
int asize, size;
size_t asize, size;
} cmark_strbuf;

extern unsigned char cmark_strbuf__initbuf[];
Expand All @@ -26,7 +26,7 @@ extern unsigned char cmark_strbuf__oom[];
* For the cases where GH_BUF_INIT cannot be used to do static
* initialization.
*/
void cmark_strbuf_init(cmark_strbuf *buf, int initial_size);
void cmark_strbuf_init(cmark_strbuf *buf, size_t initial_size);

/**
* Attempt to grow the buffer to hold at least `target_size` bytes.
Expand All @@ -36,7 +36,7 @@ void cmark_strbuf_init(cmark_strbuf *buf, int initial_size);
* existing buffer content will be preserved, but calling code must handle
* that buffer was not expanded.
*/
int cmark_strbuf_try_grow(cmark_strbuf *buf, int target_size, bool mark_oom);
int cmark_strbuf_try_grow(cmark_strbuf *buf, size_t target_size, bool mark_oom);

/**
* Grow the buffer to hold at least `target_size` bytes.
Expand All @@ -46,7 +46,7 @@ int cmark_strbuf_try_grow(cmark_strbuf *buf, int target_size, bool mark_oom);
*
* @return 0 on success or -1 on failure
*/
int cmark_strbuf_grow(cmark_strbuf *buf, int target_size);
int cmark_strbuf_grow(cmark_strbuf *buf, size_t target_size);

void cmark_strbuf_free(cmark_strbuf *buf);
void cmark_strbuf_swap(cmark_strbuf *buf_a, cmark_strbuf *buf_b);
Expand All @@ -68,9 +68,9 @@ size_t cmark_strbuf_len(const cmark_strbuf *buf);

int cmark_strbuf_cmp(const cmark_strbuf *a, const cmark_strbuf *b);

void cmark_strbuf_attach(cmark_strbuf *buf, unsigned char *ptr, int asize);
void cmark_strbuf_attach(cmark_strbuf *buf, unsigned char *ptr, size_t asize);
unsigned char *cmark_strbuf_detach(cmark_strbuf *buf);
void cmark_strbuf_copy_cstr(char *data, int datasize, const cmark_strbuf *buf);
void cmark_strbuf_copy_cstr(char *data, size_t datasize, const cmark_strbuf *buf);

static inline const char *cmark_strbuf_cstr(const cmark_strbuf *buf)
{
Expand All @@ -87,20 +87,20 @@ static inline const char *cmark_strbuf_cstr(const cmark_strbuf *buf)
* return code of these functions and call them in a series then just call
* cmark_strbuf_oom at the end.
*/
int cmark_strbuf_set(cmark_strbuf *buf, const unsigned char *data, int len);
int cmark_strbuf_set(cmark_strbuf *buf, const unsigned char *data, size_t len);
int cmark_strbuf_sets(cmark_strbuf *buf, const char *string);
int cmark_strbuf_putc(cmark_strbuf *buf, int c);
int cmark_strbuf_put(cmark_strbuf *buf, const unsigned char *data, int len);
int cmark_strbuf_put(cmark_strbuf *buf, const unsigned char *data, long len);
int cmark_strbuf_puts(cmark_strbuf *buf, const char *string);
int cmark_strbuf_printf(cmark_strbuf *buf, const char *format, ...)
CMARK_ATTRIBUTE((format (printf, 2, 3)));
int cmark_strbuf_vprintf(cmark_strbuf *buf, const char *format, va_list ap);
void cmark_strbuf_clear(cmark_strbuf *buf);

int cmark_strbuf_strchr(const cmark_strbuf *buf, int c, int pos);
int cmark_strbuf_strrchr(const cmark_strbuf *buf, int c, int pos);
void cmark_strbuf_drop(cmark_strbuf *buf, int n);
void cmark_strbuf_truncate(cmark_strbuf *buf, int len);
int cmark_strbuf_strchr(const cmark_strbuf *buf, int c, size_t pos);
long cmark_strbuf_strrchr(const cmark_strbuf *buf, int c, size_t pos);
void cmark_strbuf_drop(cmark_strbuf *buf, long n);
void cmark_strbuf_truncate(cmark_strbuf *buf, size_t len);
void cmark_strbuf_rtrim(cmark_strbuf *buf);
void cmark_strbuf_trim(cmark_strbuf *buf);
void cmark_strbuf_normalize_whitespace(cmark_strbuf *s);
Expand Down
6 changes: 3 additions & 3 deletions src/chunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

typedef struct {
unsigned char *data;
int len;
size_t len;
int alloc; // also implies a NULL-terminated string
} cmark_chunk;

Expand Down Expand Up @@ -49,7 +49,7 @@ static inline void cmark_chunk_trim(cmark_chunk *c)
cmark_chunk_rtrim(c);
}

static inline int cmark_chunk_strchr(cmark_chunk *ch, int c, int offset)
static inline size_t cmark_chunk_strchr(cmark_chunk *ch, int c, size_t offset)
{
const unsigned char *p = (unsigned char *)memchr(ch->data + offset, c, ch->len - offset);
return p ? (int)(p - ch->data) : ch->len;
Expand Down Expand Up @@ -90,7 +90,7 @@ static inline cmark_chunk cmark_chunk_literal(const char *data)
return c;
}

static inline cmark_chunk cmark_chunk_dup(const cmark_chunk *ch, int pos, int len)
static inline cmark_chunk cmark_chunk_dup(const cmark_chunk *ch, size_t pos, size_t len)
{
cmark_chunk c = {ch->data + pos, len, 0};
return c;
Expand Down
6 changes: 3 additions & 3 deletions src/cmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ cmark_node_set_literal(cmark_node *node, const char *content);

/** Returns the header level of 'node', or 0 if 'node' is not a header.
*/
CMARK_EXPORT int
CMARK_EXPORT size_t
cmark_node_get_header_level(cmark_node *node);

/** Sets the header level of 'node', returning 1 on success and 0 on error.
Expand Down Expand Up @@ -357,7 +357,7 @@ cmark_node_get_start_line(cmark_node *node);

/** Returns the column at which 'node' begins.
*/
CMARK_EXPORT int
CMARK_EXPORT size_t
cmark_node_get_start_column(cmark_node *node);

/** Returns the line on which 'node' ends.
Expand All @@ -367,7 +367,7 @@ cmark_node_get_end_line(cmark_node *node);

/** Returns the column at which 'node' ends.
*/
CMARK_EXPORT int
CMARK_EXPORT size_t
cmark_node_get_end_column(cmark_node *node);

/**
Expand Down
Loading