Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mgos_conf_parse_msg() #553

Merged
merged 1 commit into from
Oct 1, 2020
Merged

Add mgos_conf_parse_msg() #553

merged 1 commit into from
Oct 1, 2020

Conversation

kzyapkov
Copy link
Collaborator

This version of the function is identical to mgos_conf_parse() but
allows the caller to get an error message when parsing or data type
checks fail.

mg_asprintf(msg, 0, "[%s] invalid string", path);
LOG(LL_ERROR, (*msg));
if (ctx->msg) {
*ctx->msg = *msg;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to make sure *msg doesn't leak.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A note saying it should be freed by the caller?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that'd be nice (in the header).
but when it's not provided, we should still not be leaking.

@kzyapkov kzyapkov force-pushed the shelly branch 2 times, most recently from e7a1d90 to eaeb470 Compare September 29, 2020 06:03
@rojer
Copy link
Collaborator

rojer commented Sep 30, 2020

did you go back to stack buffer + stdup? i think mg_asprintf will still work, we just need to free it on return if the pointer was not provided by the user. will save an extra copy and 100 bytes of stack

@kzyapkov
Copy link
Collaborator Author

did you go back to stack buffer + stdup?

I did indeed. There are too many return statements and the code doesn't look cleaner, but I guess I can refactor it with a goto fin;

@rojer
Copy link
Collaborator

rojer commented Sep 30, 2020

oh no, it should be easier: all you need to do is to have mgos_conf_parse_off always provide non-null ctx.msg to mgos_conf_parse_cb to use but free it before returning if it was a local variable and pass on to the user if it was provided by the user.

This version of the function is identical to mgos_conf_parse() but
allows the caller to get an error message when parsing or data type
checks fail.
@rojer rojer merged commit 6093ecc into cesanta:master Oct 1, 2020
@rojer
Copy link
Collaborator

rojer commented Oct 1, 2020

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants