Fixed a temporary solution of server shutting down to an assert(0) when a too large...
authorPerttu Ahola <celeron55@gmail.com>
Tue, 3 May 2011 14:33:51 +0000 (17:33 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Tue, 3 May 2011 14:33:51 +0000 (17:33 +0300)
src/mapblock.cpp
src/utility.h

index f84c651765a31cd269018fa21545e9fe336f78ca..67e7e25740bbaf5c01cd5a9f821b4aa6b5ea77b1 100644 (file)
@@ -2109,9 +2109,17 @@ void MapBlock::serialize(std::ostream &os, u8 version)
                {
                        if(version <= 15)
                        {
-                               std::ostringstream oss(std::ios_base::binary);
-                               m_node_metadata.serialize(oss);
-                               os<<serializeString(oss.str());
+                               try{
+                                       std::ostringstream oss(std::ios_base::binary);
+                                       m_node_metadata.serialize(oss);
+                                       os<<serializeString(oss.str());
+                               }
+                               // This will happen if the string is longer than 65535
+                               catch(SerializationError &e)
+                               {
+                                       // Use an empty string
+                                       os<<serializeString("");
+                               }
                        }
                        else
                        {
index 5cb3080a7337b638b57d45055b8948344c49b698..12d732bea8d03ffca666787b8730ffc5efe860c3 100644 (file)
@@ -1911,7 +1911,9 @@ inline v3f intToFloat(v3s16 p, f32 d)
 // Creates a string with the length as the first two bytes
 inline std::string serializeString(const std::string &plain)
 {
-       assert(plain.size() <= 65535);
+       //assert(plain.size() <= 65535);
+       if(plain.size() > 65535)
+               throw SerializationError("String too long for serializeString");
        char buf[2];
        writeU16((u8*)&buf[0], plain.size());
        std::string s;