summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/mapdef.cc
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2008-11-29 12:05:46 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2008-11-29 12:05:46 +0000
commit3544990ee578f9f69a2c2f53589b2ccbe6d857d9 (patch)
treedcf66d67f202b3e5524f9b8ab96914037b31d157 /crawl-ref/source/mapdef.cc
parent54a8ee37c5d6bee4ed77eef17bad080c0f81b175 (diff)
downloadcrawl-ref-3544990ee578f9f69a2c2f53589b2ccbe6d857d9.tar.gz
crawl-ref-3544990ee578f9f69a2c2f53589b2ccbe6d857d9.zip
Make .des file depth-parse stricter, fixed default-depth for minitomb.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@7684 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/mapdef.cc')
-rw-r--r--crawl-ref/source/mapdef.cc16
1 files changed, 13 insertions, 3 deletions
diff --git a/crawl-ref/source/mapdef.cc b/crawl-ref/source/mapdef.cc
index 9954147c62..617b4c2c8d 100644
--- a/crawl-ref/source/mapdef.cc
+++ b/crawl-ref/source/mapdef.cc
@@ -47,6 +47,16 @@ static const char *map_section_names[] = {
"float",
};
+// atoi that rejects strings containing non-numeric trailing characters.
+// returns defval for invalid input.
+template <typename V>
+static V strict_aton(const char *s, V defval = 0)
+{
+ char *end;
+ const V res = strtol(s, &end, 10);
+ return (!*s || *end) ? defval : res;
+}
+
const char *map_section_name(int msect)
{
if (msect < 0 || msect >= MAP_NUM_SECTION_TYPES)
@@ -234,19 +244,19 @@ void level_range::parse_depth_range(const std::string &s, int *l, int *h)
std::string::size_type hy = s.find('-');
if (hy == std::string::npos)
{
- *l = *h = atoi(s.c_str());
+ *l = *h = strict_aton<int>(s.c_str());
if (!*l)
throw std::string("Bad depth: ") + s;
}
else
{
- *l = atoi(s.substr(0, hy).c_str());
+ *l = strict_aton<int>(s.substr(0, hy).c_str());
std::string tail = s.substr(hy + 1);
if (tail.empty())
*h = 100;
else
- *h = atoi(tail.c_str());
+ *h = strict_aton<int>(tail.c_str());
if (!*l || !*h || *l > *h)
throw std::string("Bad depth: ") + s;