[PR #1105] [MERGED] Clean up some misuses of INVALID_HANDLE_VALUE (fixes #427) #24479

Open
opened 2026-01-31 09:03:32 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/1105
Author: @metathinker
Created: 6/2/2019
Status: Merged
Merged: 6/4/2019
Merged by: @miniksa

Base: masterHead: invalid_handle_value


📝 Commits (3)

  • dff2c8d s/INVALID_HANDLE_VALUE/nullptr/
  • ef8d096 undo some riskier changes
  • 3693a94 went back to INVALID_HANDLE_VALUE in VtConsole, added null check on function pointer ctor arg

📊 Changes

8 files changed (+18 additions, -24 deletions)

View changed files

📝 src/cascadia/TerminalConnection/ConhostConnection.h (+1 -1)
📝 src/host/PtySignalInputThread.cpp (+1 -1)
📝 src/host/VtInputThread.cpp (+1 -1)
📝 src/host/ft_host/CJK_DbcsTests.cpp (+0 -2)
📝 src/interactivity/onecore/ConIoSrvComm.cpp (+4 -4)
📝 src/renderer/gdi/paint.cpp (+1 -1)
📝 src/tools/vtpipeterm/VtConsole.cpp (+5 -9)
📝 src/tools/vtpipeterm/VtConsole.hpp (+5 -5)

📄 Description

Almost all functions in the Windows API that open or create objects and return HANDLEs to them return null on failure; only a few (mostly to do with the file system) return INVALID_HANDLE_VALUE on failure. This PR scrubs the repo of a few, but not necessarily all, cases where INVALID_HANDLE_VALUE was mistakenly used or tested against instead of null. In particular, it fixes 2 cases reported in issue #427 where the return value of CreateThread() was compared against INVALID_HANDLE_VALUE against null, causing the error handling code to run at the wrong time.

There are a lot of other uses of INVALID_HANDLE_VALUE I found that looked questionable, but which I left alone. Most of these were used to initialize HANDLE-typed variables and as a sentinel to see if those variables remained unset to a "real" value.

PR Checklist

  • Fixes Writing into inactive screen buffer is broken (#427)
  • CLA signed - N/A; I work for Microsoft
  • Tests added/passed - no tests added, existing unit tests pass
  • Requires documentation to be updated - N/A; no doc changes needed
  • I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan.

References

This PR was inspired by my previous PR #1015 which also resolved some misuses of INVALID_HANDLE_VALUE.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/1105 **Author:** [@metathinker](https://github.com/metathinker) **Created:** 6/2/2019 **Status:** ✅ Merged **Merged:** 6/4/2019 **Merged by:** [@miniksa](https://github.com/miniksa) **Base:** `master` ← **Head:** `invalid_handle_value` --- ### 📝 Commits (3) - [`dff2c8d`](https://github.com/microsoft/terminal/commit/dff2c8d93b4620bd090e53fd9b31002ec0fbccd4) s/INVALID_HANDLE_VALUE/nullptr/ - [`ef8d096`](https://github.com/microsoft/terminal/commit/ef8d096b222a3c2a150e801c052ee5120f6cc52e) undo some riskier changes - [`3693a94`](https://github.com/microsoft/terminal/commit/3693a94a46b8d6b7fa510bb1b15b45d853bcfaef) went back to INVALID_HANDLE_VALUE in VtConsole, added null check on function pointer ctor arg ### 📊 Changes **8 files changed** (+18 additions, -24 deletions) <details> <summary>View changed files</summary> 📝 `src/cascadia/TerminalConnection/ConhostConnection.h` (+1 -1) 📝 `src/host/PtySignalInputThread.cpp` (+1 -1) 📝 `src/host/VtInputThread.cpp` (+1 -1) 📝 `src/host/ft_host/CJK_DbcsTests.cpp` (+0 -2) 📝 `src/interactivity/onecore/ConIoSrvComm.cpp` (+4 -4) 📝 `src/renderer/gdi/paint.cpp` (+1 -1) 📝 `src/tools/vtpipeterm/VtConsole.cpp` (+5 -9) 📝 `src/tools/vtpipeterm/VtConsole.hpp` (+5 -5) </details> ### 📄 Description Almost all functions in the Windows API that open or create objects and return HANDLEs to them return null on failure; only a few (mostly to do with the file system) return INVALID_HANDLE_VALUE on failure. This PR scrubs the repo of a few, but not necessarily all, cases where INVALID_HANDLE_VALUE was mistakenly used or tested against instead of null. In particular, it fixes 2 cases reported in issue #427 where the return value of [CreateThread()](https://docs.microsoft.com/windows/desktop/api/processthreadsapi/nf-processthreadsapi-createthread) was compared against INVALID_HANDLE_VALUE against null, causing the error handling code to run at the wrong time. There are a lot of other uses of INVALID_HANDLE_VALUE I found that looked questionable, but which I left alone. Most of these were used to initialize HANDLE-typed variables and as a sentinel to see if those variables remained unset to a "real" value. ### PR Checklist * [x] Fixes #427 * [x] CLA signed - N/A; I work for Microsoft * [x] Tests added/passed - no tests added, existing unit tests pass * [x] Requires documentation to be updated - N/A; no doc changes needed * [ ] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. ### References This PR was inspired by my previous PR #1015 which also resolved some misuses of INVALID_HANDLE_VALUE. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:03:32 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#24479