This was caught by a static analyzer some time ago.

Tested on x86-64/Windows, applied on the mainline.


2025-10-24  Eric Botcazou  <[email protected]>

        PR ada/98879
        * terminals.c (__gnat_setup_child_communication) [_WIN32]: Add else
        blocks in the processing of the data returned by ReadFile.

-- 
Eric Botcazou
diff --git a/gcc/ada/terminals.c b/gcc/ada/terminals.c
index 89f887556c0..85a5c0dcbd9 100644
--- a/gcc/ada/terminals.c
+++ b/gcc/ada/terminals.c
@@ -724,13 +724,16 @@ __gnat_setup_child_communication
     if (bRet == FALSE) {
       cpid = -1;
     }
-
-    dwRet = buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
-    if (dwRet != 0) {
-      cpid = -1;
+    else {
+      dwRet = buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
+      if (dwRet != 0) {
+	cpid = -1;
+      }
+      else {
+	cpid = buf[4] | (buf[5] << 8) | (buf[6] << 16) | (buf[7] << 24);
+      }
     }
 
-    cpid = buf[4] | (buf[5] << 8) | (buf[6] << 16) | (buf[7] << 24);
     process->pid = cpid;
   }
 

Reply via email to