-
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
Open
fm-117
wants to merge
3
commits into
develop
Choose a base branch
from
2306-nullpointerexception-in-diagnosticutilsadderrornode-node-string-message-symbolreference-symbol-messagecode-code
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
TypeCobol.Test/Parser/Programs/Cobol85/RedefinesWithReplace.PGM.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- Diagnostics --- | ||
Line 10[34,40] <27, Error, Syntax> - Syntax error : mismatched input ':zoneA:' expecting user defined word RuleStack=codeElement>dataDescriptionEntry>redefinesClause>dataNameReference, OffendingSymbol=[34,40::zoneA:]<PartialCobolWord> | ||
Line 10[8,41] <30, Error, Semantics> - Semantic error: Illegal REDEFINES: Target cannot be identified | ||
|
||
--- Program --- | ||
PROGRAM: TCOBCOMP common:False initial:False recursive:False | ||
author: ? written: ? compiled: ? installation: ? security: ? | ||
--- Intrinsic:Namespace:Program:Global:Local | ||
-- DATA -------- | ||
zone1:Alphanumeric | ||
zone1-redef:Alphanumeric | ||
z-label:Alphanumeric | ||
z-content:Alphanumeric | ||
--- Intrinsic | ||
-- TYPES ------- | ||
BOOL:BOOL | ||
DATE:DATE | ||
CURRENCY:CURRENCY | ||
STRING:STRING |
16 changes: 16 additions & 0 deletions
16
TypeCobol.Test/Parser/Programs/Cobol85/RedefinesWithReplace.rdz.cbl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
IDENTIFICATION DIVISION. | ||
PROGRAM-ID. TCOBCOMP. | ||
DATA DIVISION. | ||
WORKING-STORAGE SECTION. | ||
REPLACE ==:zone:== BY ==zone1==. | ||
01 :zone: PIC X(120). | ||
* Undefined REDEFINES target, we get 2 diagnostics: | ||
* - one for the invalid parsing of the Redefines entry | ||
* - one for the invalid semantics of the REDEFINES | ||
01 :zone:-redef REDEFINES :zoneA:. | ||
05 z-label PIC X(20). | ||
05 z-content PIC X(100). | ||
PROCEDURE DIVISION. | ||
GOBACK | ||
. | ||
END PROGRAM TCOBCOMP. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,8 @@ internal CharacterValue CreateFigurativeConstant(CodeElementsParser.FigurativeCo | |
if (context.symbolicCharacterReference() != null) | ||
{ | ||
var symbolicCharacterReference = CreateSymbolicCharacterReference(context.symbolicCharacterReference()); | ||
System.Diagnostics.Debug.Assert(symbolicCharacterReference.NameLiteral != null); | ||
System.Diagnostics.Debug.Assert(symbolicCharacterReference.NameLiteral.Token != null); | ||
return new CharacterValue(symbolicCharacterReference); | ||
} | ||
|
||
|
@@ -172,6 +174,8 @@ private RepeatedCharacterValue CreateRepeatedCharacterValue([CanBeNull] Token al | |
if (context.symbolicCharacterReference() != null) | ||
{ | ||
var symbolicCharacterReference = CreateSymbolicCharacterReference(context.symbolicCharacterReference()); | ||
System.Diagnostics.Debug.Assert(symbolicCharacterReference.NameLiteral != null); | ||
System.Diagnostics.Debug.Assert(symbolicCharacterReference.NameLiteral.Token != null); | ||
return new RepeatedCharacterValue(allToken, symbolicCharacterReference); | ||
} | ||
|
||
|
@@ -803,7 +807,13 @@ internal SymbolReference CreateIndexNameReference(CodeElementsParser.QualifiedIn | |
|
||
var reference = CreateQualifiedSymbolReference(new SymbolReference(headLiteral, SymbolType.IndexName), new SymbolReference(CreateAlphanumericValue(tail[0]), SymbolType.IndexName), false); | ||
for (int c = 1; c < tail.Length; c++) reference = CreateQualifiedSymbolReference(reference, new SymbolReference(CreateAlphanumericValue(tail[c]), SymbolType.IndexName), false); | ||
symbolInformationForTokens[reference.NameLiteral.Token] = reference; | ||
|
||
var token = reference.NameLiteral?.Token; | ||
if (token != null) | ||
{ | ||
symbolInformationForTokens[token] = reference; | ||
} | ||
|
||
Comment on lines
+810
to
+816
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code is repeated 4 times. Similar factorization with method:
|
||
return reference; | ||
} | ||
|
||
|
@@ -871,7 +881,12 @@ internal SymbolReference CreateQualifiedParagraphNameReference(CodeElementsParse | |
private SymbolReference CreateQualifiedParagraphNameReference(CodeElementsParser.ParagraphNameReferenceContext head, CodeElementsParser.SectionNameReferenceContext tail, bool isCOBOL = true) | ||
{ | ||
var reference = CreateQualifiedSymbolReference(CreateParagraphNameReference(head), CreateSectionNameReference(tail), isCOBOL); | ||
symbolInformationForTokens[reference.NameLiteral.Token] = reference; | ||
var token = reference.NameLiteral?.Token; | ||
if (token != null) | ||
{ | ||
symbolInformationForTokens[token] = reference; | ||
} | ||
|
||
return reference; | ||
} | ||
|
||
|
@@ -912,9 +927,11 @@ private SymbolReference CreateQualifiedDataName(CodeElementsParser.DataNameRefer | |
} | ||
qname = CreateQualifiedSymbolReference(qname, current, isCOBOL); | ||
} | ||
if (qname != null) | ||
|
||
var token = qname?.NameLiteral?.Token; | ||
if (token != null) | ||
{ | ||
symbolInformationForTokens[qname.NameLiteral.Token] = qname; | ||
symbolInformationForTokens[token] = qname; | ||
return qname; | ||
} | ||
|
||
|
@@ -954,7 +971,13 @@ private SymbolReference CreateQualifiedConditionName(CodeElementsParser.Conditio | |
qname = CreateQualifiedSymbolReference(qname, part, isCOBOL); | ||
} | ||
} | ||
symbolInformationForTokens[qname.NameLiteral.Token] = qname; | ||
|
||
var token = qname.NameLiteral?.Token; | ||
if (token != null) | ||
{ | ||
symbolInformationForTokens[token] = qname; | ||
} | ||
|
||
return qname; | ||
} | ||
|
||
|
@@ -1015,7 +1038,12 @@ private SymbolReference CreateQualifiedDataNameOrQualifiedConditionNameTCFunctio | |
{ | ||
var reference = CreateQualifiedSymbolReference(CreateDataNameReferenceOrConditionNameReferenceOrConditionForUPSISwitchNameReferenceOrTCFunctionProcedure(head), CreateDataNameReferenceOrFileNameReferenceOrMnemonicForUPSISwitchNameReference(tail[0]), isCOBOL); | ||
for (int c = 1; c < tail.Length; c++) reference = CreateQualifiedSymbolReference(reference, CreateDataNameReferenceOrFileNameReferenceOrMnemonicForUPSISwitchNameReference(tail[c]), isCOBOL); | ||
symbolInformationForTokens[reference.NameLiteral.Token] = reference; | ||
var token = reference.NameLiteral?.Token; | ||
if (token != null) | ||
{ | ||
symbolInformationForTokens[token] = reference; | ||
} | ||
|
||
return reference; | ||
} | ||
|
||
|
@@ -1134,7 +1162,12 @@ internal ExternalName CreateQualifiedTextName(CodeElementsParser.QualifiedTextNa | |
{ | ||
ExternalName libraryName = CreateLibraryName(context.libraryName()); | ||
var qualifiedTextName = new QualifiedTextName(textName, libraryName); | ||
symbolInformationForTokens[qualifiedTextName.NameLiteral.Token] = qualifiedTextName; | ||
var textNameToken = qualifiedTextName.NameLiteral?.Token; | ||
if (textNameToken != null) | ||
{ | ||
symbolInformationForTokens[textNameToken] = qualifiedTextName; | ||
} | ||
|
||
return qualifiedTextName; | ||
} | ||
} | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
Calll it like this;
AddToSymbolInformation(specialRegister.DataDescriptionEntry?.DataName, specialRegister.SymbolReference);