Simplify error node
[babeltrace.git] / formats / ctf / metadata / ctf-parser.y
index 1ccc718a0954ff063e72cefc7c3bd69b75ff6961..40cf65e9a03605922d631a83bcb7b0bc49dccdd1 100644 (file)
@@ -83,6 +83,15 @@ static const char *node_type_to_str[] = {
 #undef ENTRY
 };
 
+/*
+ * Static node for out of memory errors. Only "type" is used. lineno is
+ * always left at 0. The rest of the node content can be overwritten,
+ * but is never used.
+ */
+static struct ctf_node error_node = {
+       .type = NODE_ERROR,
+};
+
 BT_HIDDEN
 const char *node_type(struct ctf_node *node)
 {
@@ -327,8 +336,10 @@ static struct ctf_node *make_node(struct ctf_scanner *scanner,
        struct ctf_node *node;
 
        node = malloc(sizeof(*node));
-       if (!node)
-               return NULL;
+       if (!node) {
+               printfl_fatal(yyget_lineno(scanner->scanner), "out of memory");
+               return &error_node;
+       }
        memset(node, 0, sizeof(*node));
        node->type = type;
        node->lineno = yyget_lineno(scanner->scanner);
@@ -338,6 +349,7 @@ static struct ctf_node *make_node(struct ctf_scanner *scanner,
 
        switch (type) {
        case NODE_ROOT:
+               node->type = NODE_ERROR;
                printfn_fatal(node, "trying to create root node");
                break;
 
@@ -418,6 +430,7 @@ static struct ctf_node *make_node(struct ctf_scanner *scanner,
 
        case NODE_UNKNOWN:
        default:
+               node->type = NODE_ERROR;
                printfn_fatal(node, "unknown node type '%d'", (int) type);
                break;
        }
This page took 0.02442 seconds and 4 git commands to generate.