Skip to content

Correct review comment: ptr.add(0) on a dangling pointer is not UB#19798

Closed
Copilot wants to merge 1 commit intoom/02-26-feat_data_structures_add_codebuffer_print_strs_array_from
copilot/sub-pr-19760
Closed

Correct review comment: ptr.add(0) on a dangling pointer is not UB#19798
Copilot wants to merge 1 commit intoom/02-26-feat_data_structures_add_codebuffer_print_strs_array_from
copilot/sub-pr-19760

Conversation

Copy link
Contributor

Copilot AI commented Feb 26, 2026

A previous automated review comment incorrectly claimed that calling .add(0) on a dangling pointer (e.g., from a zero-capacity Vec) is undefined behavior under strict provenance, and suggested adding an early-return guard.

The claim is wrong. The Rust ptr::add documentation explicitly scopes the provenance/in-bounds requirement to non-zero offsets:

"If the computed offset is non-zero, then self must be derived from a pointer to some allocation..."

For add(0), the computed offset is 0 * size_of::<u8>() = 0, so no provenance requirement applies. The existing code in print_strs_array_with_total_len is sound as-is — no fast-path guard is needed.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copy link
Contributor Author

Copilot AI commented Feb 26, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • doc.rust-lang.org
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] WIP address feedback on CodeBuffer::print_strs_array Correct review comment: ptr.add(0) on a dangling pointer is not UB Feb 26, 2026
@overlookmotel overlookmotel deleted the copilot/sub-pr-19760 branch February 26, 2026 23:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants