summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/map_knowledge.h
diff options
context:
space:
mode:
authorNeil Moore <neil@s-z.org>2013-10-17 00:27:55 -0400
committerNeil Moore <neil@s-z.org>2013-10-17 01:11:42 -0400
commit24edc4cae90feec2497818a2ea75cb8a9c4167ec (patch)
tree6cc250b199c6cd29d783dc6b56af19d0c39de5cf /crawl-ref/source/map_knowledge.h
parent660d43f70c72e38673d5e3210e52afd2d1f0450d (diff)
downloadcrawl-ref-24edc4cae90feec2497818a2ea75cb8a9c4167ec.tar.gz
crawl-ref-24edc4cae90feec2497818a2ea75cb8a9c4167ec.zip
Avoid an MSVC crash on dry fountains etc (xFleury)
map_cell has a bit field "dungeon_feature_type _feat:8", which MSVC makes signed. However, some dungeon_feature_type enumerators are greater than 127 (beginning with DNGN_DRY_FOUNTAIN = 128). That results in some bounds errors when encountering one of those features. According to the C++ standard, 8 bits should be large enough to hold the enum (§7.2 [dcl.enum] paragraph 7), so the values in the bit field should compare equal to the corresponding enumerators (§9.6 [class.bit] paragraph 4). So it sounds like MSVC is in the wrong. Still, work around it by casting to uint8_t and then to the full enum type. At this point maybe we should just use a uint8_t instead of a bit field (since we have to cast anyway). However, that doesn't look as nice in gdb...
Diffstat (limited to 'crawl-ref/source/map_knowledge.h')
-rw-r--r--crawl-ref/source/map_knowledge.h5
1 files changed, 4 insertions, 1 deletions
diff --git a/crawl-ref/source/map_knowledge.h b/crawl-ref/source/map_knowledge.h
index c044538c69..d8ad79e3ab 100644
--- a/crawl-ref/source/map_knowledge.h
+++ b/crawl-ref/source/map_knowledge.h
@@ -120,7 +120,10 @@ struct map_cell
dungeon_feature_type feat() const
{
- return _feat;
+ // Ugh; MSVC makes the bit field signed even though that means it can't
+ // actually hold all the enum values. That seems to be in contradiction
+ // of the standard (§9.6 [class.bit] paragraph 4) but what can you do?
+ return dungeon_feature_type(uint8_t(_feat));
}
unsigned feat_colour() const