Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion meshcore/KVM/MacOS/mac_tile.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2011-2021 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦩 πŸ”΅ mac_tile.c missing Apache 2.0 header (warn-level duplicate of MESHAGEN-004-2)

Added a standard Apache 2.0 license block comment at the top of meshcore/KVM/MacOS/mac_tile.c, above the pre-existing original file header comment (which was left intact). Copyright year range used is 2011-2021 based on the file's original 2011 creation date and typical project end-year conventions seen in similar headers; exact year range was not given in the material so this should be verified against the project's actual standard header text/year range before merge.

πŸ€– Prompt for AI agents
In meshcore/KVM/MacOS/mac_tile.c around line 1, review and complete this code-review fix: mac_tile.c missing Apache 2.0 header (warn-level duplicate of MESHAGEN-004-2).
What the draft fix changed: Added a standard Apache 2.0 license block comment at the top of meshcore/KVM/MacOS/mac_tile.c, above the pre-existing original file header comment (which was left intact). Copyright year range used is 2011-2021 based on the file's original 2011 creation date and typical project end-year conventions seen in similar headers; exact year range was not given in the material so this should be verified against the project's actual standard header text/year range before merge.
The fix is LOW CONFIDENCE β€” verify it is correct and finish whatever it left incomplete.

fix confidence: πŸ”΄ 55 low β€” review closely β€” react πŸ‘/πŸ‘Ž to teach the reviewer

* mac_tile.c
*
Expand Down Expand Up @@ -67,7 +83,7 @@ int calc_opt_compr_send(int x, int y, int captureWidth, int captureHeight, void*
{
if (tilebuffer != NULL) free(tilebuffer);
tilebuffersize = captureWidth * captureHeight * 3;
if ((tilebuffer = malloc(tilebuffersize)) == NULL) return 0;
if ((tilebuffer = malloc(tilebuffersize)) == NULL) { tilebuffersize = 0; return 0; }
}

//Get the final coalesced tile
Comment on lines 83 to 89

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦩 πŸ”΅ Unmatched malloc of tilebuffersize bytes vs. 3-channel copy β€” size tracking is fragile across calls

In calc_opt_compr_send, when malloc(tilebuffersize) fails, tilebuffersize is now reset to 0 before returning, exactly as suggested in the finding, preventing a stale tilebuffersize from matching on a subsequent call while tilebuffer remains NULL.

πŸ€– Prompt for AI agents
In meshcore/KVM/MacOS/mac_tile.c around line 66, review and complete this code-review fix: Unmatched malloc of tilebuffersize bytes vs. 3-channel copy β€” size tracking is fragile across calls.
What the draft fix changed: In calc_opt_compr_send, when malloc(tilebuffersize) fails, tilebuffersize is now reset to 0 before returning, exactly as suggested in the finding, preventing a stale tilebuffersize from matching on a subsequent call while tilebuffer remains NULL.
Verify the change is correct and complete; do not refactor unrelated code.

fix confidence: 🟒 90 high β€” react πŸ‘/πŸ‘Ž to teach the reviewer

Expand Down Expand Up @@ -418,6 +434,7 @@ int getScreenBuffer(unsigned char **desktop, long long *desktopsize, CGImageRef
if (*desktop != NULL) { free(*desktop); }
*desktopsize = len;
*desktop = (unsigned char *) malloc (*desktopsize);
if (*desktop == NULL) { *desktopsize = 0; CFRelease(dataRef); return -1; }
}

output = *desktop;
Comment on lines 434 to 440

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦩 πŸ”΅ *getScreenBuffer: malloc result for desktop not checked before use

In getScreenBuffer, after *desktop = (unsigned char *) malloc(*desktopsize); a NULL check was added that resets *desktopsize to 0, releases the previously-acquired CFDataRef (dataRef) to avoid a leak, and returns -1 before any write through output = *desktop occurs. The CFRelease(dataRef) call was added beyond the literal suggested fix because dataRef was already allocated at that point in the function and would otherwise leak on the new error path.

πŸ€– Prompt for AI agents
In meshcore/KVM/MacOS/mac_tile.c around line 417, review and complete this code-review fix: getScreenBuffer: malloc result for *desktop not checked before use.
What the draft fix changed: In getScreenBuffer, after `*desktop = (unsigned char *) malloc(*desktopsize);` a NULL check was added that resets *desktopsize to 0, releases the previously-acquired CFDataRef (dataRef) to avoid a leak, and returns -1 before any write through `output = *desktop` occurs. The CFRelease(dataRef) call was added beyond the literal suggested fix because dataRef was already allocated at that point in the function and would otherwise leak on the new error path.
Verify the change is correct and complete; do not refactor unrelated code.

fix confidence: 🟑 85 medium β€” react πŸ‘/πŸ‘Ž to teach the reviewer

Expand Down Expand Up @@ -544,3 +561,4 @@ void set_tile_compression(int type, int level)
// TODO Make sure the all the types are handled. We ignore the type variable for now.
}