这是indexloc提供的服务,不要输入任何密码
Skip to content

Segfault on mpca_lang instanciation #8

@oleiade

Description

@oleiade

Hi!

I've been working around the examples in the readme (which by the way are not really up to date), and buildyourownlisp. Updating mpc today lead me to get a segfault on my mpca_lang instanciation.

It seems to be a problem with a NULL pointer manipulation, but don't really have the time to dig in it right now, any clue?

example source

#include <stdio.h>
#include <stdlib.h>

#include "mpc.h"

int                     main(int argc, char** argv) {
        mpc_parser_t    *Expr = mpc_new("expr");
        mpc_parser_t    *Value = mpc_new("value");
        mpc_parser_t    *Maths = mpc_new("maths");
        mpc_result_t    result;
        char*           input = "123";

        mpca_lang(MPCA_LANG_DEFAULT,
        "                                       \
        expression  : <value> ;                 \
        value       : /[0-9]+/ | <expression> ; \
        maths       : /^/ <expression> /$/ ;    \
        ",
        Expr, Value, Maths);

        if (mpc_parse("input", input, Value, &result)) {
                mpc_ast_print(result.output);
                mpc_ast_delete(result.output);
        } else {
                mpc_err_print(result.error);
                mpc_err_delete(result.error);
        }

        mpc_cleanup(3, Expr, Value, Maths);
}

gdb session

(gdb) b main
Breakpoint 1 at 0x400dfc: file src/main.c, line 7.
(gdb) r
Starting program: /home/oleiade/Dev/Sandbox/C/config/./bin/debug/config 

Breakpoint 1, main (argc=1, argv=0x7fffffffe148) at src/main.c:7
7           mpc_parser_t    *Expr = mpc_new("expr");
(gdb) n
8           mpc_parser_t    *Value = mpc_new("value");
(gdb) 
9           mpc_parser_t    *Maths = mpc_new("maths");
(gdb) 
11          char*           input = "123";
(gdb) 
13          mpca_lang(MPCA_LANG_DEFAULT,
(gdb) 

Program received signal SIGSEGV, Segmentation fault.
0x0000000000409e46 in mpca_grammar_find_parser (x=0x618c10 "expression", st=0x7fffffffdf40) at src/mpc.c:2886
2886          if (p->name && strcmp(p->name, x) == 0) { return p; }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions