Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Void codemethod call should not crash#4850

Merged
lzybkr merged 3 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
powercode:void_codemethodpowercode/PowerShell:void_codemethodCopy head branch name to clipboard
Sep 20, 2017
Merged

Void codemethod call should not crash#4850
lzybkr merged 3 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
powercode:void_codemethodpowercode/PowerShell:void_codemethodCopy head branch name to clipboard

Conversation

@powercode

Copy link
Copy Markdown
Collaborator

Fixes #4826

Adding a check if the method to be called is void, and in that case wrap it in a block that returns null.

Looking at some other code, there seems to be a CSharpBinderFlags.ResultDiscarded when they to this in C#. Can reviewers please check if this or something similar needs to be used here?

@lzybkr lzybkr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just one small change and I think it's good.

Expression expr = InvokeMethod(codeMethod.CodeReference, null, args.Prepend(target).ToArray(), false, MethodInvocationType.Ordinary);
if (codeMethod.CodeReference.ReturnType == typeof(void))
{
expr = Expression.Block(expr, Expression.Default(typeof(object)));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should be:

                    expr = Expression.Block(expr, ExpressionCache.AutomationNullConstant);

Otherwise it might be possible to use the return value.

@lzybkr lzybkr merged commit 916ef56 into PowerShell:master Sep 20, 2017
@vors vors removed their request for review September 25, 2017 00:33
@powercode powercode deleted the void_codemethod branch January 26, 2018 19:04
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.

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.