Description: Only return the "status" value from "wait" if the result is
 non-zero. The calling code in the Posix structure converts the status result
 to a value of type exit_status even if the pid is zero.  The result is
 ignored in that case but it can result in a Fail exception if the status is
 invalid.
Origin: backport, https://github.com/polyml/polyml/commit/ba608ceb1dbc20db934bd01b0bccdd50c08ac4e9
Author: David Matthews <dm@prolingua.co.uk>
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/libpolyml/unix_specific.cpp
+++ b/libpolyml/unix_specific.cpp
@@ -1256,7 +1256,7 @@
     int callFlags = get_C_long(taskData, DEREFHANDLE(args)->Get(2));
     int flags = callFlags | WNOHANG; // Add in WNOHANG so we never block.
     pid_t pres = 0;
-    int status;
+    int status = 0;
     switch (kind)
     {
     case 0: /* Wait for any child. */
@@ -1292,7 +1292,8 @@
     {
         Handle result, pidHandle, resHandle;
         pidHandle = Make_arbitrary_precision(taskData, pres);
-        resHandle = Make_arbitrary_precision(taskData, status);
+        // If the pid is zero status may not be a valid value and may overflow.
+        resHandle = Make_arbitrary_precision(taskData, pres == 0 ? 0: status);
 
         result = ALLOC(2);
         DEREFHANDLE(result)->Set(0, DEREFWORDHANDLE(pidHandle));
