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

Possibly unnecessarily complicated va_start/va_end in get_double #181

Open
rillig opened this issue Aug 19, 2019 · 0 comments
Open

Possibly unnecessarily complicated va_start/va_end in get_double #181

rillig opened this issue Aug 19, 2019 · 0 comments
Assignees

Comments

@rillig
Copy link

rillig commented Aug 19, 2019

The implementation of get_double and the similar functions initializes the va_list ap at the beginning of the function and cleans it up before each return statement. This seems unnecessarily complicated and error-prone. (The current implementation is fine, it just has potential to become erroneous.)

A simpler way would be:

while (true)
{
    // Get line of text
    va_list ap;
    va_start(ap, format);
    string line = get_string(&ap, format);
    va_end(ap);

    // Return DBL_MAX on failure
    if (line == NULL)
    {
        return DBL_MAX;
    }

This code has the benefit of making the actual scope of ap smaller than before, and of pairing the va_start with the va_end in an obvious way.

Is there a compelling reason for the current implementation?

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

No branches or pull requests

2 participants