|
From: Charles L. <da...@sy...> - 2001-03-24 16:11:45
|
>This crashes the scanner:
>
>1/27/01 3:48:56p Sensurr gives you 2 coins for the stone.
>1/28/01 5:47:04p Sensurr gives you 2 coins for the stone.
>
>I took a look at it but couldnt figure out why exactly. Lark?
the problem is with the following function in CScribiaDoc.h:
string& rename(string s) {
return (mRename.find(s) != mRename.end() ? mRename[s] : s);
}
the function accepts a string but returns a string&. if s is indeed found
in the map there's no problem; it returns a reference to a string entry in
the map. but if s is not found it returns a reference to *s*. but s is
deleted when the function returns!
i don't think changing the argument to "string& s" would work, since many
times this function is called with a char* (thus creating, again, a
temporary string object).
the best solution is to change the return value to "string". however this
is *very* different from a return value of "string&", since the latter
allows one to modify the content of a map entry in mRename. i've looked
over the places where rename is used, and i don't see it used in that
intent. so, i've changed the function to this:
string rename(const string& s) {
return (mRename.find(s) != mRename.end() ? mRename[s] : s);
}
and i've changed line 897 in Scribia.l from
const string& theItem = rename(yytext);
to
string theItem = rename(yytext);
this solves the crashing problem and doesn't seem to cause other problems
so i've committed my changes.
Checking in scribia/Source/CScribiaDoc.h;
/cvsroot/scribia/scribia/Source/CScribiaDoc.h,v <-- CScribiaDoc.h
new revision: 1.21; previous revision: 1.20
done
Checking in scribia/Source/Scribia.l;
/cvsroot/scribia/scribia/Source/Scribia.l,v <-- Scribia.l
new revision: 1.33; previous revision: 1.32
done
nevertheless, Lark, if you could confirm that rename wasn't to be used to
change the returning string, i'd feel better. thanks!
--
charles lechasseur - da...@sy...
http://www3.sympatico.ca/danov/marathon/
"The butts of evil are awaiting my bootprints!"
- Minsc
|