We have this function prototype:
BNode *b_new_node(const char *name, int pos, int len, const char *val);
Most of the code using this(and similar) are autogenerated code, and looks like:
b = b_new_node("foo.bar.id.1", 0, 10, some_data);
The function allocates a new BNode and copies the val
string into it, but it just assigns the name
member to a pointer, e.g.
b_strlcpy(new_node->val, val, sizeof new_node->val);
new_node->name = name;
This wrecks havoc if the first argument in b_new_node("foo.bar.id.1", 0, 10, some_data); is not a string literal, or otherwise something with static storage duration, but e.g. a buffer on the stack.
Is there anyway, with gcc (other compilers are of interest too), we can have a compile time check that this argument is passed in is of static storage ?
(ofcourse the easy way to avoid these possible problems is to copy that argument too into the node - the measurements we did with that approach rises the memory need by 50% and slows the program down by 10%, so that approach is undesirable).