-
Notifications
You must be signed in to change notification settings - Fork 25
WI #2306 Protect against NullReferenceException when reading NameLiteral property #2801
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
base: develop
Are you sure you want to change the base?
Conversation
var dataName = specialRegister.DataDescriptionEntry?.DataName; | ||
var dataNameToken = dataName?.NameLiteral?.Token; | ||
if (dataNameToken != null) | ||
{ | ||
CobolWordsBuilder.symbolInformationForTokens[dataNameToken] = dataName; | ||
} | ||
if (specialRegister.SymbolReference != null) { | ||
CobolWordsBuilder.symbolInformationForTokens[specialRegister.SymbolReference.NameLiteral.Token] = specialRegister.SymbolReference; | ||
|
||
var specialRegisterReference = specialRegister.SymbolReference; | ||
var specialRegisterReferenceToken = specialRegisterReference?.NameLiteral?.Token; | ||
if (specialRegisterReferenceToken != null) | ||
{ | ||
CobolWordsBuilder.symbolInformationForTokens[specialRegisterReferenceToken] = specialRegisterReference; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is repeated 3 times.
It could be factorized in a methode AddToSymbolInformation with this code:
private void AddToSymbolInformation(SymbolDefinition specialRegisterName, SymbolReference specialRegisterReference)
{
var specialRegisterNameToken = specialRegisterName?.NameLiteral?.Token;
if (specialRegisterNameToken != null)
{
CobolWordsBuilder.symbolInformationForTokens[specialRegisterNameToken] = specialRegisterName;
}
var specialRegisterReferenceToken = specialRegisterReference?.NameLiteral?.Token;
if (specialRegisterReferenceToken != null)
{
CobolWordsBuilder.symbolInformationForTokens[specialRegisterReferenceToken] = specialRegisterReference;
}
}
Calll it like this;
AddToSymbolInformation(specialRegister.DataDescriptionEntry?.DataName, specialRegister.SymbolReference);
|
||
var token = reference.NameLiteral?.Token; | ||
if (token != null) | ||
{ | ||
symbolInformationForTokens[token] = reference; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is repeated 4 times. Similar factorization with method:
private void AddToSymbolInformation(SymbolReference reference)
{
var token = reference.NameLiteral?.Token;
if (token != null)
{
symbolInformationForTokens[token] = reference;
}
}
Fixes #2306
The
NullReferenceException
regularly observed in theAddError
method when checkingREDEFINES
may be caused by:NameLiteral
beingnull
Token
of theNameLiteral
beingnull
.This PR aims at fixing unsafe uses of
SymbolInformation.NameLiteral
.