Skip to content

Is iio_err() supposed to return 0 for NULL pointers? #1266

@schwesinger

Description

@schwesinger

Hi,

I'm using sth. like the following code snippet to setup IIO devices and channels:

dev = iio_context_find_device(ctx, "iio-device-name");
err = iio_err(dev);
if (err) shutdown();
ch = iio_device_find_channel(dev, "voltage0", false);

In the normal case this works as expected. To test the error paths in my code, I just unloaded the IIO kernel driver being used and was greated with a null-ptr deref on dev in iio_device_find_channel(). The error could be easily fixed with an explicit NULL check:

if (err || !dev) shutdown();

However, I wondered if iio_err() should handle this case implicitly to reduce the error handling boilerplate for users?

Edit: This was observed on 2c5c1f8.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions