chEvtGetAndClearFlags(...) does not mask events Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
User avatar
FXCoder
Posts: 384
Joined: Sun Jun 12, 2016 4:10 am
Location: Sydney, Australia
Has thanked: 180 times
Been thanked: 130 times

chEvtGetAndClearFlags(...) does not mask events  Topic is solved

Postby FXCoder » Wed Sep 05, 2018 4:20 pm

chEvtGetAndClearFlags(..) returns all flags set on the event source.
It should only return those in the mask.
This causes an issue if using chEvtDispatch(...) to execute functions.
i.e. flags outside the expected masked range will access invalid pointer(s).

Code: Select all

Index: chevents.c
===================================================================
--- chevents.c   (revision 12234)
+++ chevents.c   (working copy)
@@ -262,7 +262,7 @@
   elp->flags = (eventflags_t)0;
   chSysUnlock();
 
-  return flags;
+  return flags & elp->wflags;
 }
 
 /**


User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: chEvtGetAndClearFlags(...) does not mask events

Postby Giovanni » Wed Sep 05, 2018 6:15 pm

Very good point :shock:

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: chEvtGetAndClearFlags(...) does not mask events

Postby Giovanni » Thu Sep 06, 2018 1:53 pm

Hi,

Fixed as bug #977.

Giovanni

User avatar
FXCoder
Posts: 384
Joined: Sun Jun 12, 2016 4:10 am
Location: Sydney, Australia
Has thanked: 180 times
Been thanked: 130 times

Re: chEvtGetAndClearFlags(...) does not mask events

Postby FXCoder » Thu Sep 13, 2018 3:53 am

The fix does not seem to be in the trunk repo?

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: chEvtGetAndClearFlags(...) does not mask events

Postby Giovanni » Thu Sep 13, 2018 8:03 am

Hi,

It is in trunk.

Code: Select all

eventflags_t chEvtGetAndClearFlagsI(event_listener_t *elp) {
  eventflags_t flags;

  flags = elp->flags;
  elp->flags = (eventflags_t)0;

  return flags & elp->wflags;
}


Giovanni

User avatar
FXCoder
Posts: 384
Joined: Sun Jun 12, 2016 4:10 am
Location: Sydney, Australia
Has thanked: 180 times
Been thanked: 130 times

Re: chEvtGetAndClearFlags(...) does not mask events

Postby FXCoder » Thu Sep 13, 2018 8:13 am

Needs to be fixed in two places....
The non I version doesn't call the I version.
Maybe it should be changed to do so?

Code: Select all

/**
 * @brief   Returns the flags associated to an @p event_listener_t.
 * @details The flags are returned and the @p event_listener_t flags mask is
 *          cleared.
 *
 * @param[in] elp       pointer to the @p event_listener_t structure
 * @return              The flags added to the listener by the associated
 *                      event source.
 *
 * @api
 */
eventflags_t chEvtGetAndClearFlags(event_listener_t *elp) {
  eventflags_t flags;

  chSysLock();
  flags = elp->flags;
  elp->flags = (eventflags_t)0;
  chSysUnlock();

  return flags;
}

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: chEvtGetAndClearFlags(...) does not mask events

Postby Giovanni » Wed Sep 19, 2018 1:55 pm

Hi,

Fixed both functions now, thanks.

Giovanni


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 12 guests