Found the error, was treating all nodes the same even though the struct has an enum.
typedef struct ast {
node_t type;
union {
struct {
struct ast *node_l;
struct ast *node_r;
};
char *value;
};
} ast_t;
So,when the eval function reached a leaf node it was trying to access a string rather than a pointer to another node. Fix it by handling the eval function better.