Update device.c

Fix for Out-of-bounds write error(Overrunning array)