On Tue, Mar 22, 2011 at 11:17:46AM -0700, Jason Gerecke wrote:
> On Mon, Mar 21, 2011 at 9:16 PM, Peter Hutterer
> <[email protected]> wrote:
> > +/**
> > + * Flip the mask bit in buttons corresponding to btn to the specified 
> > state.
> > + *
> > + * @param buttons The current button mask
> > + * @param btn Zero-indexed button number to change
> > + * @param state Zero to unset, non-zero to set the mask for the button
> > + *
> > + * @return The new button mask
> > + */
> > +static int mod_buttons(int buttons, int btn, int state)
> > +{
> > +       int mask = 1 << btn;
> > +
> > +       if (btn >= sizeof(int))
> > +       {
> > +               xf86Msg(X_ERROR, "%s: Invalid button number %d. 
> > Insufficient "
> > +                               "storage\n", __func__, btn);
> > +               return buttons;
> > +       }
> > +
> > +       if (state)
> > +               buttons |= mask;
> > +       else
> > +               buttons &= ~mask;
> > +
> > +       return buttons;
> > +}
> >
> 
> Would it be too nitpicky of me to want the shift occuring after the
> test? I do prefer it when functions fail as fast as possible...

sure, why not. I've squashed this diff in:

diff --git a/src/wcmUSB.c b/src/wcmUSB.c
index 44f802c..f1c7c53 100644
--- a/src/wcmUSB.c
+++ b/src/wcmUSB.c
@@ -1040,7 +1040,7 @@ static int usbParseAbsEvent(WacomCommonPtr common,
  */
 static int mod_buttons(int buttons, int btn, int state)
 {
-       int mask = 1 << btn;
+       int mask;
 
        if (btn >= sizeof(int))
        {
@@ -1049,6 +1049,8 @@ static int mod_buttons(int buttons, int btn, int state)
                return buttons;
        }
 
+       mask = 1 << btn;
+
        if (state)
                buttons |= mask;
        else
 
Cheers,
  Peter

------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software 
be a part of the solution? Download the Intel(R) Manageability Checker 
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
Linuxwacom-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to