Page 1 of 1

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

Posted: Wed Sep 05, 2018 4:20 pm
by FXCoder
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;
 }
 
 /**


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

Posted: Wed Sep 05, 2018 6:15 pm
by Giovanni
Very good point :shock:

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

Posted: Thu Sep 06, 2018 1:53 pm
by Giovanni
Hi,

Fixed as bug #977.

Giovanni

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

Posted: Thu Sep 13, 2018 3:53 am
by FXCoder
The fix does not seem to be in the trunk repo?

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

Posted: Thu Sep 13, 2018 8:03 am
by Giovanni
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

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

Posted: Thu Sep 13, 2018 8:13 am
by FXCoder
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;
}

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

Posted: Wed Sep 19, 2018 1:55 pm
by Giovanni
Hi,

Fixed both functions now, thanks.

Giovanni