Skip to content

Conversation

Savagedlight
Copy link
Contributor

NOTE: This code is based on pull request 4 (asprintf ENOMEM checks). The diff will be significantly smaller once that PR is merged.

This removes all the manual calls to cleanup(), as they were always near the end of the code path, and uses atexit() (stdlib) to call cleanup() instead. It also improves the asprintf_check_enomem() function.

Check if asprintf calls failed due to not enough memory, and if so,
print a message to stderr and abort()
@allanjude
Copy link
Owner

I would actually do this slightly differently

call the function: asprintf_checked()
and make it take the arguments of asprintf, and call the asprintf for you (actually it would likely use vasprintf to just pass the var-args along)

so:
int asprintf(&var, "fmt", var, ...);

would become:
void asprintf_checked(&var, "fmt", var, ...);

instead of:
asprintf_check_enomem(asprintf(&var, "fmt", var, ...));

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