aboutsummaryrefslogtreecommitdiffstats
path: root/prism
diff options
context:
space:
mode:
authorNathan Froyd <froydnj@gmail.com>2023-09-29 15:56:07 -0400
committergit <svn-admin@ruby-lang.org>2023-09-29 20:41:23 +0000
commitf88f5b59e8cd58f5a88013d192c8141ea0bb8499 (patch)
tree33308876778b4af65879f174388cccf7b2cda688 /prism
parente05ea03553fcbbbf194dbf4cd982898480ae141b (diff)
downloadruby-f88f5b59e8cd58f5a88013d192c8141ea0bb8499.tar.gz
[ruby/prism] remove `peek_string` to avoid subtle memory issues
https://github.com/ruby/prism/commit/f393d30ce1
Diffstat (limited to 'prism')
-rw-r--r--prism/prism.c13
1 files changed, 1 insertions, 12 deletions
diff --git a/prism/prism.c b/prism/prism.c
index f8c0beb327..d333e5e8f2 100644
--- a/prism/prism.c
+++ b/prism/prism.c
@@ -5017,17 +5017,6 @@ peek(pm_parser_t *parser) {
return peek_at(parser, parser->current.end);
}
-// Get the next string of length len in the source starting from parser->current.end.
-// If the string extends beyond the end of the source, return the empty string ""
-static inline const uint8_t *
-peek_string(pm_parser_t *parser, size_t len) {
- if (parser->current.end + len <= parser->end) {
- return parser->current.end;
- } else {
- return (const uint8_t *) "";
- }
-}
-
// If the character to be read matches the given value, then returns true and
// advanced the current pointer.
static inline bool
@@ -6636,7 +6625,7 @@ parser_lex(pm_parser_t *parser) {
// = => =~ == === =begin
case '=':
- if (current_token_starts_line(parser) && memcmp(peek_string(parser, 5), "begin", 5) == 0 && pm_char_is_whitespace(peek_offset(parser, 5))) {
+ if (current_token_starts_line(parser) && (parser->current.end + 5 <= parser->end) && memcmp(parser->current.end, "begin", 5) == 0 && pm_char_is_whitespace(peek_offset(parser, 5))) {
pm_token_type_t type = lex_embdoc(parser);
if (type == PM_TOKEN_EOF) {