Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0002035Core InformPhrases and functional programmingpublic2017-10-18 14:242017-11-03 18:27
Reporterclimbingstars 
Assigned To 
PriorityhighSeveritycriticalReproducibilityalways
StatusnewResolutionopen 
Platformx86OSLinuxOS VersionAny
Product Version6M62 
Target VersionFixed in Version 
Summary0002035: Inform crashes with a stack overflow when appending to indexed text variables.
DescriptionInform crashes with a stack overflow when any second command is typed.
Minimal Source Text To Reproduce
"Test"

The data string is an indexed text that varies.

After reading a command:
if the data string is "" begin;
now the data string is unpunctuated word number 2 in the description of the player;
otherwise;
now the data string is "[data string] [unpunctuated word number 2 in the description of the player]";

end if;
say the data string.

The Testing Room is A Room.
Additional InformationIt looks like the issue is with the data string appending line.
TagsNo tags attached.
Effect(critical) Compiler crashes
Attached Files

- Relationships

-  Notes
(0004738)
zarf (developer)
2017-10-18 14:30

I haven't tested this code, but you're creating a substitution which includes itself. This will crash the VM because it expands infinitely.

I don't remember if there's a recommended way to append strings. You can probably make it work by creating a temporary value which is "the substituted form of ..." and then copying it back to data string.
(0004739)
climbingstars (reporter)
2017-10-19 12:48

But this works perfectly!

"Test"

The data string is an indexed text that varies.

After reading a command:
repeat with counter running from 1 to the number of words in the description of the player begin;
if the data string is "" begin;
now the data string is unpunctuated word number counter in the description of the player;
otherwise;
now the data string is "[data string] [unpunctuated word number counter in the description of the player]";
end if;
end repeat;
say the data string.

The Testing Room is A Room.

Surely this should fail too if that were the case.
(0004744)
zarf (developer)
2017-10-22 17:09

I did some debugging to verify that, yes, the VM gets into an infinite loop of expanding the [data string] substitution.

Why doesn't your second example fail? I don't know. There may be some internal detail about how indexed text is handled which makes that case fail to fail in the way you expect. It's still best to avoid it by using a "substituted form" phrase.
(0004745)
climbingstars (reporter)
2017-10-30 16:58

On checking the auto.inf file after compiling, I noticed some differences.

The first example generates this.

BlkValueCopy((Global_Vars-->10), (TEXT_TY_ExpandIfPerishable((I7SFRAME+WORDSIZE*2),TX_S_135)));

While the second generates this for the same line where "tmp_0" is the counter variable.

BlkValueCopy((Global_Vars-->10), ((LocalParking-->0=tmp_0),TEXT_TY_ExpandIfPerishable((I7SFRAME+WORDSIZE*2),TX_S_135)));

Maybe if Inform were to use this second case for the first example, it would work fine. Either way if this is not the best way to append strings, it would be nicer for inform to reject the code rather than crash at run time.
(0004746)
climbingstars (reporter)
2017-10-31 12:52

It still fails even with the temporary variable!

"Test"

The data string is an indexed text that varies.

After reading a command:
if the data string is "" begin;
now the data string is unpunctuated word number 2 in the description of the player;
otherwise;
let temporary be "[data string] [unpunctuated word number 2 in the description of the player]";
now the data string is temporary;
end if;
say the data string.

The Testing Room is A Room.
(0004747)
mattweiner (reporter)
2017-11-03 18:27

From WwI ยง20.7:

"What's going on here is this: Inform substitutes text immediately if it contains references to a temporary value such as "T", and otherwise only if it needs to access the contents."

In the first example climbingstars posted above, the line

now the data string is "[data string] [unpunctuated word number counter in the description of the player]";

contains a reference to the temporary variable "counter," so I think this means that the text gets substituted immediately, so you don't get the infinite loop.

In the thing you posted just above, you didn't make "temporary" a substituted form, so you've just created a temporary text variable that calls data string as a function. Then you set data string to that function and data string is still calling itself.

Anyhow the way to do this appending is to use the substituted form right away, and you don't need a temporary variable. So you can put this in the original text and it will work:

now the data string is the substituted form of "[data string] [unpunctuated word number 2 in the description of the player]";

- Issue History
Date Modified Username Field Change
2017-10-18 14:24 climbingstars New Issue
2017-10-18 14:30 zarf Note Added: 0004738
2017-10-19 12:48 climbingstars Note Added: 0004739
2017-10-22 17:09 zarf Note Added: 0004744
2017-10-30 16:58 climbingstars Note Added: 0004745
2017-10-31 12:52 climbingstars Note Added: 0004746
2017-11-03 18:27 mattweiner Note Added: 0004747


Copyright © 2000 - 2010 MantisBT Group
Powered by Mantis Bugtracker