purduesigbots / pros

Source code for PROS kernel: open source C/C++ development for the VEX V5 microcontroller
https://pros.cs.purdue.edu
Other
259 stars 76 forks source link

In some cases, vision_read_by_size will return an error without setting errno #536

Closed nickmertin closed 1 year ago

nickmertin commented 1 year ago

Expected Behavior:

Anytime an error code is returned from any API function, errno should be set to indicate the error which occured.

Actual Behavior:

Initially, vision_read_by_size fills the signature of each element in the output array with VISION_OBJ_ERR_SIG. If object_count is greater than the number of available objects (as given by vexDeviceVisionObjectCountGet), then one or more entries at the end of the array will not be touched by the second for loop, leaving them with a value which signifies that an error occurred. Meanwhile, unless an actual error occurs in the underlying VEX API, errno will not be set, leaving it at whatever value it happened to be when the function was called.

Steps to reproduce:

I don't have the hardware to test, but you should be able to reproduce by requesting more objects than exist. Try setting errno to something distinctive before calling vision_read_by_size and note that it won't have changed afterwards.

System information:

Platform: V5 PROS Kernel Version: latest develop branch

nickmertin commented 1 year ago

Never mind, please ignore. I just noticed that the function returns the number of objects actually read, which solves this problem.