Suggestion: Error/warning writing to constant string

Started by RickJ, Thu 27/01/2005 17:07:35

Previous topic - Next topic

RickJ

I did a bone head thing that took me a couple of days to figure out.  The story goes something like this.  I made a function called Delete(string section, string option) that deletes a single option value pair from an ini type configuration file.  If option is a blank string it deletes the entire section.   Delete calls nextopt(string option, value) functions which finds the next option in the file and copies the option name to OPTION and the value string to VALUE.  Ok, so far so good.   Now I make a test and call Delete("mysec", ""), so when nextopt() copies the option name to its parameter OPTION it actually is being copied to "".   After this really bizzare things start to happen making it difficult to find out what is actually going on. 

So I am wondering if it would be possible or practical for the compiler to check for someone writting to constant strings that are automatically created by AGS (i.e. "", "constant string created by AGS", etc).   So that if you did a StrCopy("", "#hit happens") there would be an error message telling that you can't write to a constant string.   

Late last night I began composing a bug report but decided not to post it when I wrote "I'll probably regret posting this in the morning...".    Were I in a different state of mind (no I don't mean inebriated  := but this problem did make me wish I was ...) or  had less programming experience I am certain I would have pressed the post button. 

Although this suggestion doesn't seem, to me, to be a high priority item, it could potentially save future headaches for all concerned.  I thought I would share my expreience and make this suggestion for whatever it is worth.     



Pumaman

The problem is that AGS doesn't have a concept of a "const string" parameter, so it can't really know whether the parameter will be written to or not. As strazer pointed out, it's on the tracker and something I'd like to fix at some point, but it's non-trivial.

RickJ

Quote
... AGS doesn't have a concept of a "const string" parameter, so it can't really know whether the parameter will be written to or not. ...  it's non-trivial.
Yeah, I thought that may be the case so that's why I used the  "possible or practical" terminology.   Now that I know what's causing it I can stop doing it. 

SMF spam blocked by CleanTalk