diff options
author | Kevin Newton <kddnewton@gmail.com> | 2023-08-07 17:19:55 -0400 |
---|---|---|
committer | Takashi Kokubun <takashikkbn@gmail.com> | 2023-08-16 17:47:32 -0700 |
commit | 77e52735f09411a94ce5ae8bdbac381bc0a49a44 (patch) | |
tree | 1e3bea081bbdd74378c6e10000b737cc3998476b /yarp/yarp.c | |
parent | 9b952670bb4945ea227a72dd9b74ef5972a69757 (diff) | |
download | ruby-77e52735f09411a94ce5ae8bdbac381bc0a49a44.tar.gz |
[ruby/yarp] Fix warnings found from gcc-analyzer and clang-analyzer
https://github.com/ruby/yarp/commit/1f9a6e05c4
Diffstat (limited to 'yarp/yarp.c')
-rw-r--r-- | yarp/yarp.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/yarp/yarp.c b/yarp/yarp.c index b1305f1209..6573a8ef40 100644 --- a/yarp/yarp.c +++ b/yarp/yarp.c @@ -505,10 +505,15 @@ yp_statements_node_body_append(yp_statements_node_t *node, yp_node_t *statement) // implement our own arena allocation. static inline void * yp_alloc_node(YP_ATTRIBUTE_UNUSED yp_parser_t *parser, size_t size) { - return malloc(size); + void *memory = malloc(size); + if (memory == NULL) { + fprintf(stderr, "Failed to allocate %zu bytes\n", size); + abort(); + } + return memory; } -#define YP_ALLOC_NODE(parser, type) (type *) yp_alloc_node(parser, sizeof(type)); if (node == NULL) return NULL +#define YP_ALLOC_NODE(parser, type) (type *) yp_alloc_node(parser, sizeof(type)) // Allocate a new MissingNode node. static yp_missing_node_t * @@ -12206,7 +12211,7 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t node = parse_target(parser, node, &operator, NULL); yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after &&="); - return (yp_node_t *) yp_call_operator_and_write_node_create(parser, call_node, &token, value); + return (yp_node_t *) yp_call_operator_and_write_node_create(parser, (yp_call_node_t *) node, &token, value); } case YP_NODE_CLASS_VARIABLE_READ_NODE: { parser_lex(parser); @@ -12311,7 +12316,7 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t node = parse_target(parser, node, &operator, NULL); yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after ||="); - return (yp_node_t *) yp_call_operator_or_write_node_create(parser, call_node, &token, value); + return (yp_node_t *) yp_call_operator_or_write_node_create(parser, (yp_call_node_t *) node, &token, value); } case YP_NODE_CLASS_VARIABLE_READ_NODE: { parser_lex(parser); @@ -12425,7 +12430,7 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t parser_lex(parser); yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after the operator."); - return (yp_node_t *) yp_call_operator_write_node_create(parser, call_node, &token, value); + return (yp_node_t *) yp_call_operator_write_node_create(parser, (yp_call_node_t *) node, &token, value); } case YP_NODE_CLASS_VARIABLE_READ_NODE: { parser_lex(parser); |