aboutsummaryrefslogtreecommitdiffstats
path: root/prism
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2023-10-13 13:40:33 -0400
committerJemma Issroff <jemmaissroff@gmail.com>2023-10-16 15:40:19 -0700
commit1ae8c624830715579dd67c5e5bd8a75514c417d3 (patch)
treea2ec958c962b50f4b5a44389b29c046afbe351f6 /prism
parent9f16f07cf1e340acd9c41acaf8d46394353a0cea (diff)
downloadruby-1ae8c624830715579dd67c5e5bd8a75514c417d3.tar.gz
[ruby/prism] Load magic comments in java
https://github.com/ruby/prism/commit/5d189ce33e
Diffstat (limited to 'prism')
-rw-r--r--prism/diagnostic.c2
-rw-r--r--prism/prism.c8
2 files changed, 5 insertions, 5 deletions
diff --git a/prism/diagnostic.c b/prism/diagnostic.c
index 7eafd8b088..09388297ba 100644
--- a/prism/diagnostic.c
+++ b/prism/diagnostic.c
@@ -265,7 +265,7 @@ pm_diagnostic_message(pm_diagnostic_id_t diag_id) {
// Append an error to the given list of diagnostic.
bool
pm_diagnostic_list_append(pm_list_t *list, const uint8_t *start, const uint8_t *end, pm_diagnostic_id_t diag_id) {
- pm_diagnostic_t *diagnostic = (pm_diagnostic_t *) malloc(sizeof(pm_diagnostic_t));
+ pm_diagnostic_t *diagnostic = (pm_diagnostic_t *) calloc(sizeof(pm_diagnostic_t), 1);
if (diagnostic == NULL) return false;
*diagnostic = (pm_diagnostic_t) { .start = start, .end = end, .message = pm_diagnostic_message(diag_id) };
diff --git a/prism/prism.c b/prism/prism.c
index 47b84a70dc..b2484d6ed7 100644
--- a/prism/prism.c
+++ b/prism/prism.c
@@ -5453,7 +5453,8 @@ parser_lex_magic_comment(pm_parser_t *parser, bool semantic_token_seen) {
// Here, we need to do some processing on the key to swap out dashes for
// underscores. We only need to do this if there _is_ a dash in the key.
pm_string_t key;
- const uint8_t *dash = pm_memchr(key_start, '-', (size_t) (key_end - key_start), parser->encoding_changed, &parser->encoding);
+ const size_t key_length = (size_t) (key_end - key_start);
+ const uint8_t *dash = pm_memchr(key_start, '-', (size_t) key_length, parser->encoding_changed, &parser->encoding);
if (dash == NULL) {
pm_string_shared_init(&key, key_start, key_end);
@@ -5475,7 +5476,6 @@ parser_lex_magic_comment(pm_parser_t *parser, bool semantic_token_seen) {
// Finally, we can start checking the key against the list of known
// magic comment keys, and potentially change state based on that.
const uint8_t *key_source = pm_string_source(&key);
- const size_t key_length = pm_string_length(&key);
// We only want to attempt to compare against encoding comments if it's
// the first line in the file (or the second in the case of a shebang).
@@ -5502,7 +5502,7 @@ parser_lex_magic_comment(pm_parser_t *parser, bool semantic_token_seen) {
// Allocate a new magic comment node to append to the parser's list.
pm_magic_comment_t *magic_comment;
- if ((magic_comment = (pm_magic_comment_t *) malloc(sizeof(pm_magic_comment_t))) != NULL) {
+ if ((magic_comment = (pm_magic_comment_t *) calloc(sizeof(pm_magic_comment_t), 1)) != NULL) {
magic_comment->key_start = key_start;
magic_comment->value_start = value_start;
magic_comment->key_length = (uint32_t) key_length;
@@ -6774,7 +6774,7 @@ parser_lex_callback(pm_parser_t *parser) {
// Return a new comment node of the specified type.
static inline pm_comment_t *
parser_comment(pm_parser_t *parser, pm_comment_type_t type) {
- pm_comment_t *comment = (pm_comment_t *) malloc(sizeof(pm_comment_t));
+ pm_comment_t *comment = (pm_comment_t *) calloc(sizeof(pm_comment_t), 1);
if (comment == NULL) return NULL;
*comment = (pm_comment_t) {