diff --git a/parse.y b/parse.y index cf8ae370aa..2075784b63 100644 --- a/parse.y +++ b/parse.y @@ -7710,6 +7710,13 @@ parser_mixed_escape(struct parser_params *p, const char *beg, rb_encoding *enc1, p->lex.pcur = pos; } +static inline char +nibble_char_upper(unsigned int c) +{ + c &= 0xf; + return c + (c < 10 ? '0' : 'A' - 10); +} + static int tokadd_string(struct parser_params *p, int func, int term, int paren, long *nest, @@ -7799,12 +7806,11 @@ tokadd_string(struct parser_params *p, pushback(p, c); c = read_escape(p, 0, enc); - int i; - char escbuf[5]; - snprintf(escbuf, sizeof(escbuf), "\\x%02X", c); - for (i = 0; i < 4; i++) { - tokadd(p, escbuf[i]); - } + char *t = tokspace(p, rb_strlen_lit("\\x00")); + *t++ = '\\'; + *t++ = 'x'; + *t++ = nibble_char_upper(c >> 4); + *t++ = nibble_char_upper(c); continue; } } diff --git a/ruby_parser.c b/ruby_parser.c index 77328d3821..6aaa867c16 100644 --- a/ruby_parser.c +++ b/ruby_parser.c @@ -774,7 +774,6 @@ rb_parser_config_initialize(rb_parser_config_t *config) config->long2int = rb_long2int; config->special_const_p = special_const_p; config->builtin_type = builtin_type; - config->snprintf = snprintf; config->node_case_when_optimizable_literal = rb_node_case_when_optimizable_literal; diff --git a/rubyparser.h b/rubyparser.h index 388f6c0c13..e95b71f049 100644 --- a/rubyparser.h +++ b/rubyparser.h @@ -601,11 +601,6 @@ typedef struct rb_parser_config_struct { int (*long2int)(long); int (*special_const_p)(VALUE); int (*builtin_type)(VALUE); -#undef snprintf - int (*snprintf)(char *str, size_t n, char const *fmt, ...); -#ifdef RUBY_SUBST_H -# define snprintf(...) ruby_snprintf(__VA_ARGS__) -#endif VALUE (*node_case_when_optimizable_literal)(const NODE *const node);