mirror of
https://github.com/RTimothyEdwards/magic.git
synced 2026-08-29 01:24:51 +02:00
The old code would only work is the fileno(stream) returned an fd in the range 0 <= 19. It would silently fail, if the fd was in the range 20..1023 because FD_SET() would work and syscall select() would be limited to only look at the first 20 fd's. Ignoring any fd's higher even if set. This would theoretically cause high CPU usage due to select() never blocking because there are no active fd's in the fd_set as far as the kernel interprets the request and the kernel would immediately return. But reading the code the 1st argument to select() seems self limiting for no good reason. It should be fileno(stream)+1 as documented in man select(2). Added the assertion as well, because we are trying to allow magic to use fd's beyond the standard environmental limits. So it becomes an assertion condition if the fd is outside the range 0..1023 because the FD_SET() macro will not operate correctly / undefined-behaviour. I can't find any user of this func in the codebase right now. If you look at sim/SimRsim.c and the use of select() there, it is correctly using select() to wait on a single fd over there. This commit changes this code to match this correct usage.
This driver is a modification of the Stanford X10 driver. The modifications were done by Walter Scott and Eric Lunow at Lawrence Livermore National Labs.