From dae9e5792a4f030ae9e748548a16a89790fbd311 Mon Sep 17 00:00:00 2001 From: tycho Date: Sun, 24 May 2015 12:56:56 +0100 Subject: Made -Weverything an error. --- src/BlockID.cpp | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'src/BlockID.cpp') diff --git a/src/BlockID.cpp b/src/BlockID.cpp index 7f0db3cfc..775d60a68 100644 --- a/src/BlockID.cpp +++ b/src/BlockID.cpp @@ -96,8 +96,7 @@ public: else { // Not a resolvable string, try pure numbers: "45:6", "45^6" etc. - a_Item.m_ItemType = (short)atoi(Split[0].c_str()); - if ((a_Item.m_ItemType == 0) && (Split[0] != "0")) + if (!StringToInteger(Split[0], a_Item.m_ItemType)) { // Parsing the number failed return false; @@ -111,9 +110,8 @@ public: a_Item.m_ItemCount = 1; return true; } - - a_Item.m_ItemDamage = (short)atoi(Split[1].c_str()); - if ((a_Item.m_ItemDamage == 0) && (Split[1] != "0")) + + if (!StringToInteger(Split[1], a_Item.m_ItemDamage)) { // Parsing the number failed return false; @@ -175,8 +173,16 @@ protected: { return; } - short ItemType = (short)atoi(Split[0].c_str()); - short ItemDamage = (Split.size() > 1) ? (short)atoi(Split[1].c_str()) : -1; + short ItemType; + if (!StringToInteger(Split[0], ItemType)) + { + ASSERT(!"Invalid item type"); + } + short ItemDamage = -1; + if (Split.size() > 1 && !StringToInteger(Split[1], ItemDamage)) + { + ASSERT(!"Invalid item damage"); + } m_Map[a_Name] = std::make_pair(ItemType, ItemDamage); } } ; @@ -288,11 +294,11 @@ AString ItemToFullString(const cItem & a_Item) eDimension StringToDimension(const AString & a_DimensionString) { // First try decoding as a number - int res = atoi(a_DimensionString.c_str()); - if ((res != 0) || (a_DimensionString == "0")) + int res; + if (!StringToInteger(a_DimensionString, res)) { // It was a valid number - return (eDimension)res; + return static_cast(res); } // Decode using a built-in map: @@ -350,7 +356,7 @@ AString DimensionToString(eDimension a_Dimension) } // for i - DimensionMap[] // Not found - LOGWARNING("Unknown dimension: \"%i\". Setting to Overworld", (int)a_Dimension); + LOGWARNING("Unknown dimension: \"%i\". Setting to Overworld", static_cast(a_Dimension)); return "Overworld"; } @@ -386,7 +392,7 @@ AString DamageTypeToString(eDamageType a_DamageType) // Unknown damage type: ASSERT(!"Unknown DamageType"); - return Printf("dtUnknown_%d", (int)a_DamageType); + return Printf("dtUnknown_%d", static_cast(a_DamageType)); } @@ -397,11 +403,11 @@ AString DamageTypeToString(eDamageType a_DamageType) eDamageType StringToDamageType(const AString & a_DamageTypeString) { // First try decoding as a number: - int res = atoi(a_DamageTypeString.c_str()); - if ((res != 0) || (a_DamageTypeString == "0")) + int res; + if (!StringToInteger(a_DamageTypeString, res)) { // It was a valid number - return (eDamageType)res; + return static_cast(res); } // Decode using a built-in map: @@ -462,7 +468,7 @@ eDamageType StringToDamageType(const AString & a_DamageTypeString) } // for i - DamageTypeMap[] // Not found: - return (eDamageType)-1; + return static_cast(-1); } -- cgit v1.2.3 From 1dfc7bbce27a60b0ded261e851956fb3d2004fab Mon Sep 17 00:00:00 2001 From: Lane Kolbly Date: Fri, 29 May 2015 16:12:51 -0500 Subject: Fixed reversed logic in StringToDimension. --- src/BlockID.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/BlockID.cpp') diff --git a/src/BlockID.cpp b/src/BlockID.cpp index 775d60a68..c598df0aa 100644 --- a/src/BlockID.cpp +++ b/src/BlockID.cpp @@ -295,7 +295,7 @@ eDimension StringToDimension(const AString & a_DimensionString) { // First try decoding as a number int res; - if (!StringToInteger(a_DimensionString, res)) + if (StringToInteger(a_DimensionString, res)) { // It was a valid number return static_cast(res); -- cgit v1.2.3