diff --git a/yarp/regexp.c b/yarp/regexp.c index c8aeaa0adb..4855859442 100644 --- a/yarp/regexp.c +++ b/yarp/regexp.c @@ -281,7 +281,9 @@ typedef enum { #define YP_REGEXP_OPTION_STATE_SLOTS (YP_REGEXP_OPTION_STATE_SLOT_MAXIMUM - YP_REGEXP_OPTION_STATE_SLOT_MINIMUM + 1) // This is the set of options that are configurable on the regular expression. -typedef struct { unsigned char values[YP_REGEXP_OPTION_STATE_SLOTS]; } yp_regexp_options_t; +typedef struct { + unsigned char values[YP_REGEXP_OPTION_STATE_SLOTS]; +} yp_regexp_options_t; // Initialize a new set of options to their default values. static void @@ -300,7 +302,7 @@ yp_regexp_options_init(yp_regexp_options_t *options) { static bool yp_regexp_options_add(yp_regexp_options_t *options, unsigned char key) { if (key >= YP_REGEXP_OPTION_STATE_SLOT_MINIMUM && key <= YP_REGEXP_OPTION_STATE_SLOT_MAXIMUM) { - key -= YP_REGEXP_OPTION_STATE_SLOT_MINIMUM; + key = (unsigned char) (key - YP_REGEXP_OPTION_STATE_SLOT_MINIMUM); switch (options->values[key]) { case YP_REGEXP_OPTION_STATE_INVALID: @@ -323,7 +325,7 @@ yp_regexp_options_add(yp_regexp_options_t *options, unsigned char key) { static bool yp_regexp_options_remove(yp_regexp_options_t *options, unsigned char key) { if (key >= YP_REGEXP_OPTION_STATE_SLOT_MINIMUM && key <= YP_REGEXP_OPTION_STATE_SLOT_MAXIMUM) { - key -= YP_REGEXP_OPTION_STATE_SLOT_MINIMUM; + key = (unsigned char) (key - YP_REGEXP_OPTION_STATE_SLOT_MINIMUM); switch (options->values[key]) { case YP_REGEXP_OPTION_STATE_INVALID: diff --git a/yarp/unescape.c b/yarp/unescape.c index 5370b27355..296caf01aa 100644 --- a/yarp/unescape.c +++ b/yarp/unescape.c @@ -64,19 +64,19 @@ unescape_octal(const char *backslash, unsigned char *value) { return 2; } - *value = (*value << 3) | (backslash[2] - '0'); + *value = (unsigned char) ((*value << 3) | (backslash[2] - '0')); if (!yp_char_is_octal_digit(backslash[3])) { return 3; } - *value = (*value << 3) | (backslash[3] - '0'); + *value = (unsigned char) ((*value << 3) | (backslash[3] - '0')); return 4; } // Convert a hexadecimal digit into its equivalent value. static inline unsigned char unescape_hexadecimal_digit(const char value) { - return (value <= '9') ? (unsigned char) (value - '0') : (value & 0x7) + 9; + return (unsigned char) ((value <= '9') ? (value - '0') : (value & 0x7) + 9); } // Scan the 1-2 digits of hexadecimal into the value. Returns the number of @@ -88,7 +88,7 @@ unescape_hexadecimal(const char *backslash, unsigned char *value) { return 3; } - *value = (*value << 4) | unescape_hexadecimal_digit(backslash[3]); + *value = (unsigned char) ((*value << 4) | unescape_hexadecimal_digit(backslash[3])); return 4; } @@ -113,22 +113,22 @@ unescape_unicode_write(char *dest, uint32_t value, const char *start, const char if (value <= 0x7F) { // 0xxxxxxx - bytes[0] = value; + bytes[0] = (unsigned char) value; return 1; } if (value <= 0x7FF) { // 110xxxxx 10xxxxxx - bytes[0] = 0xC0 | (value >> 6); - bytes[1] = 0x80 | (value & 0x3F); + bytes[0] = (unsigned char) (0xC0 | (value >> 6)); + bytes[1] = (unsigned char) (0x80 | (value & 0x3F)); return 2; } if (value <= 0xFFFF) { // 1110xxxx 10xxxxxx 10xxxxxx - bytes[0] = 0xE0 | (value >> 12); - bytes[1] = 0x80 | ((value >> 6) & 0x3F); - bytes[2] = 0x80 | (value & 0x3F); + bytes[0] = (unsigned char) (0xE0 | (value >> 12)); + bytes[1] = (unsigned char) (0x80 | ((value >> 6) & 0x3F)); + bytes[2] = (unsigned char) (0x80 | (value & 0x3F)); return 3; } @@ -136,10 +136,10 @@ unescape_unicode_write(char *dest, uint32_t value, const char *start, const char // the input is invalid. if (value <= 0x10FFFF) { // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx - bytes[0] = 0xF0 | (value >> 18); - bytes[1] = 0x80 | ((value >> 12) & 0x3F); - bytes[2] = 0x80 | ((value >> 6) & 0x3F); - bytes[3] = 0x80 | (value & 0x3F); + bytes[0] = (unsigned char) (0xF0 | (value >> 18)); + bytes[1] = (unsigned char) (0x80 | ((value >> 12) & 0x3F)); + bytes[2] = (unsigned char) (0x80 | ((value >> 6) & 0x3F)); + bytes[3] = (unsigned char) (0x80 | (value & 0x3F)); return 4; } diff --git a/yarp/util/yp_char.c b/yarp/util/yp_char.c index 1c0c20edd9..d27a04104e 100644 --- a/yarp/util/yp_char.c +++ b/yarp/util/yp_char.c @@ -75,7 +75,7 @@ yp_strspn_whitespace(const char *string, ptrdiff_t length) { // whitespace while also tracking the location of each newline. Disallows // searching past the given maximum number of characters. size_t -yp_strspn_whitespace_newlines(const char *string, long length, yp_newline_list_t *newline_list, bool stop_at_newline) { +yp_strspn_whitespace_newlines(const char *string, ptrdiff_t length, yp_newline_list_t *newline_list, bool stop_at_newline) { if (length <= 0) return 0; size_t size = 0; diff --git a/yarp/util/yp_char.h b/yarp/util/yp_char.h index dcc011f0a1..010d34d669 100644 --- a/yarp/util/yp_char.h +++ b/yarp/util/yp_char.h @@ -15,7 +15,7 @@ size_t yp_strspn_whitespace(const char *string, ptrdiff_t length); // whitespace while also tracking the location of each newline. Disallows // searching past the given maximum number of characters. size_t -yp_strspn_whitespace_newlines(const char *string, long length, yp_newline_list_t *newline_list, bool); +yp_strspn_whitespace_newlines(const char *string, ptrdiff_t length, yp_newline_list_t *newline_list, bool); // Returns the number of characters at the start of the string that are inline // whitespace. Disallows searching past the given maximum number of characters. diff --git a/yarp/util/yp_constant_pool.c b/yarp/util/yp_constant_pool.c index 8c1889c6b4..fdece2dabb 100644 --- a/yarp/util/yp_constant_pool.c +++ b/yarp/util/yp_constant_pool.c @@ -110,7 +110,7 @@ yp_constant_pool_init(yp_constant_pool_t *pool, size_t capacity) { // if any potential calls to resize fail. yp_constant_id_t yp_constant_pool_insert(yp_constant_pool_t *pool, const char *start, size_t length) { - if (pool->size >= pool->capacity * 0.75) { + if (pool->size >= (pool->capacity / 4 * 3)) { if (!yp_constant_pool_resize(pool)) return 0; } diff --git a/yarp/yarp.c b/yarp/yarp.c index f8301daa6b..f831d03ee1 100644 --- a/yarp/yarp.c +++ b/yarp/yarp.c @@ -5929,7 +5929,7 @@ parser_lex(yp_parser_t *parser) { } size_t ident_length = (size_t) (parser->current.end - ident_start); - if (quote != YP_HEREDOC_QUOTE_NONE && !match(parser, quote)) { + if (quote != YP_HEREDOC_QUOTE_NONE && !match(parser, (char) quote)) { // TODO: handle unterminated heredoc }