HuoLanguage / huo

interpreted language written in C
MIT License
213 stars 21 forks source link

Incorrect reference by import #8

Closed TheLoneWolfling closed 8 years ago

TheLoneWolfling commented 8 years ago

This:

struct Tree * imported_ast = read_import(ast->children[i]->children[0]->content.data.str);

Should be this:

struct Tree * imported_ast = read_import(ast->children[i]->children[0]->children[0]->content.data.str);

As-is, you're reading uninitialized memory.

(Sidenote: original issue exists elsewhere, but I'll pull it up if/when I stumble across it.)

incrediblesound commented 8 years ago

Good catch, I'll double check on that one. It's a little unclear when I start referencing children of children anyway, I think it might be better to store a reference in a well named variable before passing into read_import to make it clearer what is happening there.

TheLoneWolfling commented 8 years ago

I agree. This is just a "quick fix".

incrediblesound commented 8 years ago

I investigated this and it looks like the read_import function is pointing to the right value but that the tokens struct didn't like being allocated on the stack. I changed it to a heap allocation and now the "imports" example works.