On Thu, 2012-04-19 at 10:56 +1000, Peter Hutterer wrote:
> On Wed, Apr 18, 2012 at 11:41:31AM +0100, Bastien Nocera wrote:
> > On Wed, 2012-04-18 at 14:57 +1000, Peter Hutterer wrote:
> > > Add a new type WacomMatch that holds device matching information.
> > > A WacomDevice in libwacom now has a bunch of possible matches that can be
> > > queried. The first possible match is the default match unless the device 
> > > was
> > > updated otherwise (e.g. libwacom_device_new_from_path will set the correct
> > > match).
> > > 
> > > Previous calls to get bustype, vendor_id, product_id now return the set
> > > match's values.
> > > 
> > > Basic refcounting was added to the WacomDevice to allow for the device to 
> > > be
> > > stored multiple times in the device hashtable.
> > > 
> > > Signed-off-by: Peter Hutterer <peter.hutte...@who-t.net>
> > > ---
> [...]
> > > + device->matches[device->nmatches-1] = libwacom_copy_match(&match);
> > > + device->match = device->nmatches - 1;
> > > + g_free(newmatch);
> > >  }
> > >  
> > >  int libwacom_get_vendor_id(WacomDevice *device)
> > >  {
> > > -    return device->vendor_id;
> > > +    return device->matches[device->match]->vendor_id;
> > >  }
> > 
> > Add guards around public API.
> 
> I'm not sure what you mean here. Asserts?
> all other comments addressed in v2.

Something akin to that:
g_return_val_if_fail (device != NULL, -1);
g_return_val_if_fail (device->match > device->num_matches, -1);
etc.

(Showing those as programmer errors, rather than crashing). The previous
case (passing NULL to the function) would have been instantly
recognisable in a stack trace. Addressing a particular offset inside an
array that's inside a struct strikes me as particularly fragile.


------------------------------------------------------------------------------
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to