Skip to content

Commit 3563e5c

Browse files
committed
use memcmp for block memory comparison
1 parent 7a378c5 commit 3563e5c

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/util/yp_constant_pool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ yp_constant_pool_insert(yp_constant_pool_t *pool, const char *start, size_t leng
122122
// If there is a collision, then we need to check if the content is the
123123
// same as the content we are trying to insert. If it is, then we can
124124
// return the id of the existing constant.
125-
if ((constant->length == length) && strncmp(constant->start, start, length) == 0) {
125+
if ((constant->length == length) && memcmp(constant->start, start, length) == 0) {
126126
return pool->constants[index].id;
127127
}
128128

src/yarp.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4693,7 +4693,7 @@ parser_lex_encoding_comment_start(yp_parser_t *parser, const char *cursor, ptrdi
46934693

46944694
const char *cursor_limit = cursor + length - key_length + 1;
46954695
while ((cursor = yp_memchr(cursor, 'c', (size_t) (cursor_limit - cursor), parser->encoding_changed, &parser->encoding)) != NULL) {
4696-
if (strncmp(cursor, "coding", key_length - 1) == 0) {
4696+
if (memcmp(cursor, "coding", key_length - 1) == 0) {
46974697
size_t whitespace_after_coding = yp_strspn_inline_whitespace(cursor + key_length - 1, parser->end - (cursor + key_length - 1));
46984698
size_t cur_pos = key_length + whitespace_after_coding;
46994699

@@ -5211,7 +5211,7 @@ lex_keyword(yp_parser_t *parser, const char *value, yp_lex_state_t state, yp_tok
52115211
yp_lex_state_t last_state = parser->lex_state;
52125212

52135213
const size_t vlen = strlen(value);
5214-
if (parser->current.start + vlen <= parser->end && strncmp(parser->current.start, value, vlen) == 0) {
5214+
if (parser->current.start + vlen <= parser->end && memcmp(parser->current.start, value, vlen) == 0) {
52155215
if (parser->lex_state & YP_LEX_STATE_FNAME) {
52165216
lex_state_set(parser, YP_LEX_STATE_ENDFN);
52175217
} else {
@@ -5648,7 +5648,7 @@ lex_embdoc(yp_parser_t *parser) {
56485648

56495649
// If we've hit the end of the embedded documentation then we'll return that
56505650
// token here.
5651-
if (strncmp(parser->current.end, "=end", 4) == 0 &&
5651+
if (memcmp(parser->current.end, "=end", 4) == 0 &&
56525652
(parser->current.end + 4 == parser->end || yp_char_is_whitespace(parser->current.end[4]))) {
56535653
const char *newline = next_newline(parser->current.end, parser->end - parser->current.end);
56545654

@@ -6151,7 +6151,7 @@ parser_lex(yp_parser_t *parser) {
61516151

61526152
// = => =~ == === =begin
61536153
case '=':
6154-
if (current_token_starts_line(parser) && strncmp(peek_string(parser, 5), "begin", 5) == 0 && yp_char_is_whitespace(peek_offset(parser, 5))) {
6154+
if (current_token_starts_line(parser) && memcmp(peek_string(parser, 5), "begin", 5) == 0 && yp_char_is_whitespace(peek_offset(parser, 5))) {
61556155
yp_token_type_t type = lex_embdoc(parser);
61566156

61576157
if (type == YP_TOKEN_EOF) {
@@ -6816,7 +6816,7 @@ parser_lex(yp_parser_t *parser) {
68166816
if (
68176817
((parser->current.end - parser->current.start) == 7) &&
68186818
current_token_starts_line(parser) &&
6819-
(strncmp(parser->current.start, "__END__", 7) == 0) &&
6819+
(memcmp(parser->current.start, "__END__", 7) == 0) &&
68206820
(parser->current.end == parser->end || match_eol(parser))
68216821
)
68226822
{
@@ -7294,7 +7294,7 @@ parser_lex(yp_parser_t *parser) {
72947294
start += yp_strspn_inline_whitespace(start, parser->end - start);
72957295
}
72967296

7297-
if ((start + ident_length <= parser->end) && (strncmp(start, ident_start, ident_length) == 0)) {
7297+
if ((start + ident_length <= parser->end) && (memcmp(start, ident_start, ident_length) == 0)) {
72987298
bool matched = true;
72997299
bool at_end = false;
73007300

@@ -7364,7 +7364,7 @@ parser_lex(yp_parser_t *parser) {
73647364
// again and return the end of the heredoc.
73657365
if (
73667366
(start + ident_length <= parser->end) &&
7367-
(strncmp(start, ident_start, ident_length) == 0)
7367+
(memcmp(start, ident_start, ident_length) == 0)
73687368
) {
73697369
// Heredoc terminators must be followed by a newline, CRLF, or EOF to be valid.
73707370
if (

0 commit comments

Comments
 (0)