Просмотр исходного кода

Return true if is_nil() is called on forward-istantiated JSONElement. Also, never crash when is_* methods are called.

Daniele Bartolini 12 лет назад
Родитель
Сommit
032f316cdc
1 измененных файлов с 41 добавлено и 6 удалено
  1. 41 6
      engine/core/json/JSONParser.cpp

+ 41 - 6
engine/core/json/JSONParser.cpp

@@ -456,42 +456,77 @@ void JSONElement::array_value(List<float>& array)
 //--------------------------------------------------------------------------
 //--------------------------------------------------------------------------
 bool JSONElement::is_nil() const
 bool JSONElement::is_nil() const
 {
 {
-	return JSONParser::type(m_at) == JT_NIL;
+	if (m_at != NULL)
+	{
+		return JSONParser::type(m_at) == JT_NIL;
+	}
+
+	return true;
 }
 }
 
 
 //--------------------------------------------------------------------------
 //--------------------------------------------------------------------------
 bool JSONElement::is_bool() const
 bool JSONElement::is_bool() const
 {
 {
-	return JSONParser::type(m_at) == JT_BOOL;
+	if (m_at != NULL)
+	{
+		return JSONParser::type(m_at) == JT_BOOL;
+	}
+
+	return false;
 }
 }
 
 
 //--------------------------------------------------------------------------
 //--------------------------------------------------------------------------
 bool JSONElement::is_number() const
 bool JSONElement::is_number() const
 {
 {
-	return JSONParser::type(m_at) == JT_NUMBER;
+	if (m_at != NULL)
+	{
+		return JSONParser::type(m_at) == JT_NUMBER;		
+	}
+
+	return false;
 }
 }
 
 
 //--------------------------------------------------------------------------
 //--------------------------------------------------------------------------
 bool JSONElement::is_string() const
 bool JSONElement::is_string() const
 {
 {
-	return JSONParser::type(m_at) == JT_STRING;
+	if (m_at != NULL)
+	{
+		return JSONParser::type(m_at) == JT_STRING;
+	}
+
+	return false;
 }
 }
 
 
 //--------------------------------------------------------------------------
 //--------------------------------------------------------------------------
 bool JSONElement::is_array() const
 bool JSONElement::is_array() const
 {
 {
-	return JSONParser::type(m_at) == JT_ARRAY;
+	if (m_at != NULL)
+	{
+		return JSONParser::type(m_at) == JT_ARRAY;
+	}
+
+	return false;
 }
 }
 
 
 //--------------------------------------------------------------------------
 //--------------------------------------------------------------------------
 bool JSONElement::is_object() const
 bool JSONElement::is_object() const
 {
 {
-	return JSONParser::type(m_at) == JT_OBJECT;
+	if (m_at != NULL)
+	{
+		return JSONParser::type(m_at) == JT_OBJECT;
+	}
+
+	return false;
 }
 }
 
 
 //--------------------------------------------------------------------------
 //--------------------------------------------------------------------------
 uint32_t JSONElement::size() const
 uint32_t JSONElement::size() const
 {
 {
+	if (m_at == NULL)
+	{
+		return 0;
+	}
+
 	switch(JSONParser::type(m_at))
 	switch(JSONParser::type(m_at))
 	{
 	{
 		case JT_NIL:
 		case JT_NIL: