Why does using += on a nullable type result in a FORWARD_NULL defect Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceWhy does C# forbid generic attribute types?Why is Dictionary preferred over Hashtable in C#?Why is it important to override GetHashCode when Equals method is overridden?Which is preferred: Nullable<T>.HasValue or Nullable<T> != null?Nullable types and the ternary operator: why is `? 10 : null` forbidden?Type Checking: typeof, GetType, or is?Performance surprise with “as” and nullable typesThe += operator with nullable types in C#Why are generic and non-generic structs treated differently when building expression that lifts operator == to nullable?Why not inherit from List<T>?
Do working physicists consider Newtonian mechanics to be "falsified"?
Stopping real property loss from eroding embankment
Slither Like a Snake
Single author papers against my advisor's will?
Direct Experience of Meditation
Is there a documented rationale why the House Ways and Means chairman can demand tax info?
What would be Julian Assange's expected punishment, on the current English criminal law?
90's book, teen horror
Is 1 ppb equal to 1 μg/kg?
Is above average number of years spent on PhD considered a red flag in future academia or industry positions?
The following signatures were invalid: EXPKEYSIG 1397BC53640DB551
Stop battery usage [Ubuntu 18]
How to market an anarchic city as a tourism spot to people living in civilized areas?
What did Darwin mean by 'squib' here?
Active filter with series inductor and resistor - do these exist?
How is simplicity better than precision and clarity in prose?
Complexity of many constant time steps with occasional logarithmic steps
When is phishing education going too far?
Can I throw a longsword at someone?
Sorting inherited template fields
What is the electric potential inside a point charge?
How many things? AとBがふたつ
What are the performance impacts of 'functional' Rust?
Is it possible to ask for a hotel room without minibar/extra services?
Why does using += on a nullable type result in a FORWARD_NULL defect
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experienceWhy does C# forbid generic attribute types?Why is Dictionary preferred over Hashtable in C#?Why is it important to override GetHashCode when Equals method is overridden?Which is preferred: Nullable<T>.HasValue or Nullable<T> != null?Nullable types and the ternary operator: why is `? 10 : null` forbidden?Type Checking: typeof, GetType, or is?Performance surprise with “as” and nullable typesThe += operator with nullable types in C#Why are generic and non-generic structs treated differently when building expression that lifts operator == to nullable?Why not inherit from List<T>?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
No doubt there are other, perhaps better ways to do this, but I'm trying to understand what is going on here.
In the below example, coverity is reporting a FORWARD_NULL defect on the fourth line.
double? foo = null;
double bar = 1.23;
foo += bar;
System.Windows.Point point = new System.Windows.Point(foo,bar);
it reports:
assign_zero: Assigning: foo = null.
on the foo += bar line.
in += Operator (C# Reference), I see that x += y is equivalent to x = x + y, and in Using nullable types (C+ Programming Guide), I see that
These operators [the binary operator] produce a null value if one or both operands are
null
so is that what is going on? foo += bar becomes foo = foo + bar and since foo is null, foo + bar is null?
c# nullable static-analysis coverity
add a comment |
No doubt there are other, perhaps better ways to do this, but I'm trying to understand what is going on here.
In the below example, coverity is reporting a FORWARD_NULL defect on the fourth line.
double? foo = null;
double bar = 1.23;
foo += bar;
System.Windows.Point point = new System.Windows.Point(foo,bar);
it reports:
assign_zero: Assigning: foo = null.
on the foo += bar line.
in += Operator (C# Reference), I see that x += y is equivalent to x = x + y, and in Using nullable types (C+ Programming Guide), I see that
These operators [the binary operator] produce a null value if one or both operands are
null
so is that what is going on? foo += bar becomes foo = foo + bar and since foo is null, foo + bar is null?
c# nullable static-analysis coverity
Yeah, foo remains as null
– Richard Boyce
Mar 8 at 15:13
3
Is the defect being reported on line three, or is line three evidence for a defect that comes later? Normally the forward null defect is reported at the location where a null dereference can throw, but there's no such dereference here.
– Eric Lippert
Mar 8 at 16:34
@Eric Lippert you are correct. The defect is reported a few lines later where foo is being dereferenced. I'll update the question
– Michael J.
Mar 8 at 20:02
OK good, but the program fragment you gave shouldn't even compile.Point
takes a double, not a nullable double. There's no reason to run code through Coverity if it doesn't even compile!
– Eric Lippert
Mar 8 at 22:54
add a comment |
No doubt there are other, perhaps better ways to do this, but I'm trying to understand what is going on here.
In the below example, coverity is reporting a FORWARD_NULL defect on the fourth line.
double? foo = null;
double bar = 1.23;
foo += bar;
System.Windows.Point point = new System.Windows.Point(foo,bar);
it reports:
assign_zero: Assigning: foo = null.
on the foo += bar line.
in += Operator (C# Reference), I see that x += y is equivalent to x = x + y, and in Using nullable types (C+ Programming Guide), I see that
These operators [the binary operator] produce a null value if one or both operands are
null
so is that what is going on? foo += bar becomes foo = foo + bar and since foo is null, foo + bar is null?
c# nullable static-analysis coverity
No doubt there are other, perhaps better ways to do this, but I'm trying to understand what is going on here.
In the below example, coverity is reporting a FORWARD_NULL defect on the fourth line.
double? foo = null;
double bar = 1.23;
foo += bar;
System.Windows.Point point = new System.Windows.Point(foo,bar);
it reports:
assign_zero: Assigning: foo = null.
on the foo += bar line.
in += Operator (C# Reference), I see that x += y is equivalent to x = x + y, and in Using nullable types (C+ Programming Guide), I see that
These operators [the binary operator] produce a null value if one or both operands are
null
so is that what is going on? foo += bar becomes foo = foo + bar and since foo is null, foo + bar is null?
c# nullable static-analysis coverity
c# nullable static-analysis coverity
edited Mar 8 at 20:10
Michael J.
asked Mar 8 at 15:09
Michael J.Michael J.
22418
22418
Yeah, foo remains as null
– Richard Boyce
Mar 8 at 15:13
3
Is the defect being reported on line three, or is line three evidence for a defect that comes later? Normally the forward null defect is reported at the location where a null dereference can throw, but there's no such dereference here.
– Eric Lippert
Mar 8 at 16:34
@Eric Lippert you are correct. The defect is reported a few lines later where foo is being dereferenced. I'll update the question
– Michael J.
Mar 8 at 20:02
OK good, but the program fragment you gave shouldn't even compile.Point
takes a double, not a nullable double. There's no reason to run code through Coverity if it doesn't even compile!
– Eric Lippert
Mar 8 at 22:54
add a comment |
Yeah, foo remains as null
– Richard Boyce
Mar 8 at 15:13
3
Is the defect being reported on line three, or is line three evidence for a defect that comes later? Normally the forward null defect is reported at the location where a null dereference can throw, but there's no such dereference here.
– Eric Lippert
Mar 8 at 16:34
@Eric Lippert you are correct. The defect is reported a few lines later where foo is being dereferenced. I'll update the question
– Michael J.
Mar 8 at 20:02
OK good, but the program fragment you gave shouldn't even compile.Point
takes a double, not a nullable double. There's no reason to run code through Coverity if it doesn't even compile!
– Eric Lippert
Mar 8 at 22:54
Yeah, foo remains as null
– Richard Boyce
Mar 8 at 15:13
Yeah, foo remains as null
– Richard Boyce
Mar 8 at 15:13
3
3
Is the defect being reported on line three, or is line three evidence for a defect that comes later? Normally the forward null defect is reported at the location where a null dereference can throw, but there's no such dereference here.
– Eric Lippert
Mar 8 at 16:34
Is the defect being reported on line three, or is line three evidence for a defect that comes later? Normally the forward null defect is reported at the location where a null dereference can throw, but there's no such dereference here.
– Eric Lippert
Mar 8 at 16:34
@Eric Lippert you are correct. The defect is reported a few lines later where foo is being dereferenced. I'll update the question
– Michael J.
Mar 8 at 20:02
@Eric Lippert you are correct. The defect is reported a few lines later where foo is being dereferenced. I'll update the question
– Michael J.
Mar 8 at 20:02
OK good, but the program fragment you gave shouldn't even compile.
Point
takes a double, not a nullable double. There's no reason to run code through Coverity if it doesn't even compile!– Eric Lippert
Mar 8 at 22:54
OK good, but the program fragment you gave shouldn't even compile.
Point
takes a double, not a nullable double. There's no reason to run code through Coverity if it doesn't even compile!– Eric Lippert
Mar 8 at 22:54
add a comment |
1 Answer
1
active
oldest
votes
so is that what is going on? foo += bar becomes foo = foo + bar and
since foo is null, foo + bar is null?
Yes.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55066002%2fwhy-does-using-on-a-nullable-type-result-in-a-forward-null-defect%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
so is that what is going on? foo += bar becomes foo = foo + bar and
since foo is null, foo + bar is null?
Yes.
add a comment |
so is that what is going on? foo += bar becomes foo = foo + bar and
since foo is null, foo + bar is null?
Yes.
add a comment |
so is that what is going on? foo += bar becomes foo = foo + bar and
since foo is null, foo + bar is null?
Yes.
so is that what is going on? foo += bar becomes foo = foo + bar and
since foo is null, foo + bar is null?
Yes.
answered Mar 8 at 15:16
spodgerspodger
1,308913
1,308913
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55066002%2fwhy-does-using-on-a-nullable-type-result-in-a-forward-null-defect%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Yeah, foo remains as null
– Richard Boyce
Mar 8 at 15:13
3
Is the defect being reported on line three, or is line three evidence for a defect that comes later? Normally the forward null defect is reported at the location where a null dereference can throw, but there's no such dereference here.
– Eric Lippert
Mar 8 at 16:34
@Eric Lippert you are correct. The defect is reported a few lines later where foo is being dereferenced. I'll update the question
– Michael J.
Mar 8 at 20:02
OK good, but the program fragment you gave shouldn't even compile.
Point
takes a double, not a nullable double. There's no reason to run code through Coverity if it doesn't even compile!– Eric Lippert
Mar 8 at 22:54