Fix clang -Walloc-size error in CloseHandle test by removing unused WriteBuffer#125360
Fix clang -Walloc-size error in CloseHandle test by removing unused WriteBuffer#125360
Conversation
… LPDWORD allocation Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
|
@copilot is |
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes a clang -Werror,-Walloc-size build break in the PAL CloseHandle test by removing dead code that allocated an incorrectly sized buffer and was never used.
Changes:
- Removed the unused
WriteBuffervariable and itsmalloc/null-check/freecode. - Updated the stale dependency comment to no longer mention
WriteFile.
You can also share your feedback on Copilot code review. Take the survey.
| FILE_ATTRIBUTE_NORMAL, | ||
| NULL); | ||
|
|
There was a problem hiding this comment.
CreateFile return value isn't validated. If it returns INVALID_HANDLE_VALUE, the test will call CloseHandle on an invalid handle and then fail with a misleading error message (making failures hard to diagnose and potentially flaky in restricted environments). Add an explicit check after CreateFile and Fail/return when the handle is invalid (optionally including GetLastError() in the message).
| if (FileHandle == INVALID_HANDLE_VALUE) | |
| { | |
| Fail("ERROR: (Test 1) CreateFile failed with error code %u.\n", | |
| GetLastError()); | |
| PAL_Terminate(); | |
| return FAIL; | |
| } |
|
/azp run runtime-coreclr outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
WriteBufferwas declared asLPDWORDbut was allocated withsizeof(WORD)(2 bytes) and never actually used — it was never passed toWriteFileor any other function. This dead code triggered a hard-Werror,-Walloc-sizeerror in newer clang builds targetingaarch64-linux-gnu.Changes
src/coreclr/pal/tests/palsuite/miscellaneous/CloseHandle/test1/test.cpp: Remove the unusedWriteBuffervariable entirely, along with itsmalloc, null-check, andfreecalls. Also updated the stale/* Depends on: CreateFile and WriteFile */comment to/* Depends on: CreateFile */sinceWriteFilewas never called.Original prompt
This pull request was created from Copilot chat.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.