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

wrong error checks for result from iio_create_context() #1048

Open
catkira opened this issue Sep 3, 2023 · 1 comment
Open

wrong error checks for result from iio_create_context() #1048

catkira opened this issue Sep 3, 2023 · 1 comment

Comments

@catkira
Copy link
Contributor

catkira commented Sep 3, 2023

I did error checks for the result of iio_create_context like here
https://github.com/analogdevicesinc/libiio/blob/9a82e3757208630886f6aff25f723d9ca95a9501/tests/iio_stresstest.c#L252C1-L268C4

However the problem was, that in case of an error a negative value gets return which was not caught by this 'if(!ctx)'.

I changed my code to

    ctx = iio_create_context(NULL, (std::string("ip:") + ip).c_str());
    int err = iio_err(ctx);
    if (err) {
        std::cerr << "Failed to create libiio context" << std::endl;
        ctx = nullptr;
        return;
    }

and then it worked correctly.

@pcercuei
Copy link
Contributor

pcercuei commented Sep 4, 2023

Thanks, can you send a PR? Since you already have the fix 😬

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