Thu 10 Dec 2015 08:43:26 PM UTC, comment #5:
More extensive surgery will be needed. The function read_text_data() is called, essentially recursively, when trying to load a struct variable. The first time through the function it identifies that the type is a struct and then calls read_text_data for each of the "sub-variables" which are the fields of the struct.
The obvious way around this is to get the variable name, and then delay input validation, and get the variable type. After that one could decide whether to validate the variable name fully or not. But, we would also need to change the function prototype for read_text_data (and the others like read_binary_data) so that we could pass down a flag to indicate that we are still in a struct.
The backtrace is
Incidentally, the problem with the filename not being printed is caused by the fact that we vector through load_ascii() in ov.h which has the following prototype.
Because we are passing through only the istream we don't have the filename when we actually call read_text_data again. The prototype for read_text_data is shown below.
The simplest thing is probably to change the reporting and don't report information about the file name. This is fine for interactive use where the load command is proximate in time to the error message. For scripts, it's not as great because there might be multiple load commands in an m-file and you would need to set debug_on_error(1) in order to figure out which load command generated an error.
Other possibilities include changing the function prototypes to use octave_stream which has the name of the file as a member of the class. Or we could stick with istream, but change the function prototype of load_ascii to have an additional argument.
|
Wed 09 Dec 2015 08:16:34 PM UTC, comment #2:
Attached is a simple file (bad_struct.var) that contains a struct with a single invalid field name. When I try to load it I get the following.
First, there is a problem because the filename should be reported in the error message. I'll leave that aside for the time being.
Grep'ing for "bogus identifier" shows the only instance is in corefcn/ls-oct-text.cc at line 254.
If you like, we could delete the call to valid_identifier() and then presumably the file would load.
(file #35680)
|