Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move out-slice len adjustment from symbol_copy_to_slice to its caller. #1063

Merged
merged 1 commit into from
Sep 13, 2023

Conversation

graydon
Copy link
Contributor

@graydon graydon commented Sep 13, 2023

In general this is not a correct adjustment to make in symbol_copy_to_slice because that function takes an arbitrary input pos in the symbol it's copying from (like all the buffer-copy host functions). It is correct only in the case where pos == 0 and even then it represents a bit of a footgun by papering over real errors in the caller (passing too long a slice, which the caller might incorrectly assume is entirely filled by the call if the call silently succeeded).

This adjustment was added in 0bc4029 presumably in order to "make tests pass". Removing it does break tests but only because of one call path that uses this host function, where a host SymbolObject is converted to a fixed-length guest SymbolStr. This is a caller in which a zero pos is already being passed and the adjustment is appropriate, so in this commit we change that call site to do the adjustment itself (which causes all tests to pass again).

@graydon graydon requested review from sisuresh and a team as code owners September 13, 2023 20:41
In general this is not a correct adjustment to make in
symbol_copy_to_slice because that function takes an arbitrary input pos
in the symbol it's copying from (like all the buffer-copy host
functions). It is correct only in the case where pos == 0 and even then
it represents a bit of a footgun by papering over real errors in the
caller (passing too long a slice, which the caller might incorrectly
assume is entirely filled by the call if the call silently succeeded).

This adjustment was added in 0bc4029
presumably in order to "make tests pass". Removing it does break tests
but only because of one call path that uses this host function, where a
host SymbolObject is converted to a fixed-length guest SymbolStr. This is
a caller in which a zero pos is already being passed and the adjustment
is appropriate, so in this commit we change that call site to do the
adjustment itself (which causes all tests to pass again).
@graydon graydon force-pushed the symbol-copy-to-slice-size branch from 3faa0b1 to 0e0829c Compare September 13, 2023 20:54
@graydon graydon enabled auto-merge September 13, 2023 20:54
@graydon graydon added this pull request to the merge queue Sep 13, 2023
Merged via the queue into main with commit 0205cf6 Sep 13, 2023
9 checks passed
@graydon graydon deleted the symbol-copy-to-slice-size branch September 13, 2023 22:16
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