Replace only use of snprintf in parser

This commit is contained in:
Nobuyoshi Nakada 2023-08-25 23:27:52 +09:00
parent f5c8bdaa8a
commit fe73f9f24b
No known key found for this signature in database
GPG Key ID: 3582D74E1FEE4465
Notes: git 2023-08-25 15:31:31 +00:00
3 changed files with 12 additions and 12 deletions

18
parse.y
View File

@ -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;
}
}

View File

@ -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;

View File

@ -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);