- if( read(giMouseFD, &mouseinfo, sizeof(mouseinfo)) != sizeof(mouseinfo) )
- {
- // Not a 3 button mouse, oops
+ i = read(giMouseFD, data, sizeof(data));
+ i -= sizeof(*mouseinfo);
+ if( i < 0 ) {
+ _SysDebug("Mouse data undersized (no header)");
+ return ;
+ }
+ if( mouseinfo->NAxies > c_n_axies || mouseinfo->NButtons > c_n_buttons ) {
+ _SysDebug("%i axies, %i buttons above prealloc counts (%i, %i)",
+ mouseinfo->NAxies, mouseinfo->NButtons, c_n_axies, c_n_buttons
+ );
+ return ;
+ }
+ if( i < sizeof(*axies)*mouseinfo->NAxies + mouseinfo->NButtons ) {
+ _SysDebug("Mouse data undersized (body doesn't fit %i < %i)",
+ i, sizeof(*axies)*mouseinfo->NAxies + mouseinfo->NButtons
+ );