From 097e79a86de967c416d71d934a325d883d917fd5 Mon Sep 17 00:00:00 2001 From: rubidium Date: Fri, 31 Jul 2009 13:25:20 +0000 Subject: [PATCH] (svn r17001) -Codechange: replace some more assert(0)s to NOT_REACHED() and document why they (assert(0)) have to stay for the remaining cases. --- src/aircraft_cmd.cpp | 3 +-- src/openttd.cpp | 2 ++ src/strings.cpp | 3 +-- src/water_cmd.cpp | 4 ++-- src/yapf/yapf_base.hpp | 4 +--- 5 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index 8d0a3dda0f..11cea23d72 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -1799,8 +1799,7 @@ static bool AirportMove(Aircraft *v, const AirportFTAClass *apc) } while (current != NULL); DEBUG(misc, 0, "[Ap] cannot move further on Airport! (pos %d state %d) for vehicle %d", v->pos, v->state, v->index); - assert(0); - return false; + NOT_REACHED(); } /* returns true if the road ahead is busy, eg. you must wait before proceeding */ diff --git a/src/openttd.cpp b/src/openttd.cpp index 962a051433..df2996b1a9 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -116,6 +116,8 @@ void CDECL error(const char *s, ...) ShowOSErrorBox(buf, true); if (_video_driver != NULL) _video_driver->Stop(); + /* Don't go into NOT_REACHED here; NOT_REACHED is using error, so + * using it would result in an infinite loop instead of errors. */ assert(0); exit(1); } diff --git a/src/strings.cpp b/src/strings.cpp index 4cbe06df33..add90ae269 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -1248,8 +1248,7 @@ static char *GetSpecialNameString(char *buff, int ind, int64 *argv, const char * return strecpy(buff, GetScreenshotFormatDesc(i), last); } - assert(0); - return NULL; + NOT_REACHED(); } #ifdef ENABLE_NETWORK diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp index 33c53fff38..52247e8c00 100644 --- a/src/water_cmd.cpp +++ b/src/water_cmd.cpp @@ -690,13 +690,13 @@ static void GetTileDesc_Water(TileIndex tile, TileDesc *td) case WATER_CLASS_SEA: td->str = STR_WATER_DESCRIPTION_WATER; break; case WATER_CLASS_CANAL: td->str = STR_LANDINFO_CANAL; break; case WATER_CLASS_RIVER: td->str = STR_LANDINFO_RIVER; break; - default: assert(0); break; + default: NOT_REACHED(); break; } break; case WATER_TILE_COAST: td->str = STR_WATER_DESCRIPTION_COAST_OR_RIVERBANK; break; case WATER_TILE_LOCK : td->str = STR_LANDINFO_LOCK; break; case WATER_TILE_DEPOT: td->str = STR_WATER_DESCRIPTION_SHIP_DEPOT; break; - default: assert(0); break; + default: NOT_REACHED(); break; } td->owner[0] = GetTileOwner(tile); diff --git a/src/yapf/yapf_base.hpp b/src/yapf/yapf_base.hpp index b29e886e4d..c33c087776 100644 --- a/src/yapf/yapf_base.hpp +++ b/src/yapf/yapf_base.hpp @@ -275,9 +275,7 @@ public: * - PfCalcEstimate() gives too large numbers * - PfCalcCost() gives too small numbers * - You have used negative cost penalty in some cases (cost bonus) */ - assert(0); - - return; + NOT_REACHED(); } return; }