[PATCH 1/4] assert.h: Add macros to assert status and use it

Gedare Bloom gedare at rtems.org
Thu Feb 11 21:12:02 UTC 2021


On Thu, Feb 11, 2021 at 1:28 PM Ryan Long <thisisryanlong at gmail.com> wrote:
>
> These macros are to be used to check the status from calls that are flagged by
> Coverity as 'Unchecked return value'.
> ---
>  cpukit/include/rtems/score/assert.h | 30 ++++++++++++++++++++++++++++++
>  1 file changed, 30 insertions(+)
>
> diff --git a/cpukit/include/rtems/score/assert.h b/cpukit/include/rtems/score/assert.h
> index cc32448..7efaae4 100644
> --- a/cpukit/include/rtems/score/assert.h
> +++ b/cpukit/include/rtems/score/assert.h
> @@ -99,6 +99,36 @@ extern "C" {
>  #endif
>
>  /**
> + * @brief Assert if unused return value is equal.
Improve this phrase: "is equal to an expected status." maybe

> + *
> + * Assert whether @a _status and @a _value are equal and ensure @a _status is
s/whether/that

> + * marked as used when not building for debug.
> + *
> + * @param _status The return value to be checked.
> + * @param _value Indicates what @a _status is supposed to be.
> + */
> +#define _Assert_Unused_return_value_equal(_status,_value) \
I think "value_is_equal" will be better.

I think the name should be more clear that _status is a variable.
Maybe, _status_variable

Since a status can be a value. Or, call _status as _rv since it is
explicitly a returned value. It need not be a "status" indicator.

Similarily, instead of _value maybe it is better to call it
_check_value explicitly

> +        do { \
> +          _Assert((_status) == (_value)); \
> +          (void) (_status); \
> +        } while (0)
> +
> +/**
> + * @brief Assert if unused return value is not equal.

> + *
> + * Assert whether @a _status and @a _value are not equal and ensure @a _status
> + * is marked as used when not building for debug.
> + *
> + * @param _status The return value to be checked.
> + * @param _value Indicates what @a _status is not supposed to be.
> + */
> +#define _Assert_Unused_return_value_not_equal(_status,_value) \
Maybe value_is_not

same as above, use _rv instead of _status

> +         do { \
> +          _Assert((_status) != (_value)); \
> +           (void) (_status); \
> +        } while (0)
> +
> +/**
>   * @brief Returns true if thread dispatching is allowed.
>   *
>   * Thread dispatching can be repressed via _Thread_Disable_dispatch() or
> --
> 1.8.3.1
>
> _______________________________________________
> devel mailing list
> devel at rtems.org
> http://lists.rtems.org/mailman/listinfo/devel


More information about the devel mailing list