sim-se: add checks in selectFunc to fix up crashes

In selectFunc, FD_ZERO are invoked without checking whether
reinterpret_cast<fd_set *>((typename OS::fd_set *)readfds) is NULL.
So does writefds and errorfds.

Change-Id: I175fe1369c85fd8a832a227c3f90f25d772f33e1
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/53143
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
diff --git a/src/sim/syscall_emul.hh b/src/sim/syscall_emul.hh
index 6cbbf00..d78f4ac 100644
--- a/src/sim/syscall_emul.hh
+++ b/src/sim/syscall_emul.hh
@@ -2543,9 +2543,15 @@
     if (retval == -1)
         return -errno;
 
-    FD_ZERO(reinterpret_cast<fd_set *>((typename OS::fd_set *)readfds));
-    FD_ZERO(reinterpret_cast<fd_set *>((typename OS::fd_set *)writefds));
-    FD_ZERO(reinterpret_cast<fd_set *>((typename OS::fd_set *)errorfds));
+    if (readfds) {
+        FD_ZERO(reinterpret_cast<fd_set *>((typename OS::fd_set *)readfds));
+    }
+    if (writefds) {
+        FD_ZERO(reinterpret_cast<fd_set *>((typename OS::fd_set *)writefds));
+    }
+    if (errorfds) {
+        FD_ZERO(reinterpret_cast<fd_set *>((typename OS::fd_set *)errorfds));
+    }
 
     /**
      * We need to translate the host file descriptor set into a target file