diff --git a/lib/map.cpp b/lib/map.cpp index cc7002cfd..5fae11c69 100644 --- a/lib/map.cpp +++ b/lib/map.cpp @@ -539,25 +539,55 @@ void Mapa::addBlockVisTiles(CGObjectInstance * obj) } Mapa::Mapa(std::string filename) { + const int bufsize = 65536; + int mapsize = 0; + tlog0<<"Opening map file: "< mapstr; int pom; - while((pom=gzgetc(map))>=0) - { - mapstr.push_back(pom); - } + std::vector mapstr; + + // Read a map by chunks + // We could try to read the map size directly (cf RFC 1952) and then read + // directly the whole map, but that would create more problems. + do { + unsigned char *buf = new unsigned char[bufsize]; + + int ret = gzread(map, buf, bufsize); + if (ret == 0 || ret == -1) { + delete [] buf; + break; + } + + mapstr.push_back(buf); + mapsize += ret; + } while(1); + gzclose(map); - unsigned char *initTable = new unsigned char[mapstr.size()]; - for(int ss=0; ss::iterator it; + int offset; + int tocopy = mapsize; + for (it = mapstr.begin(), offset = 0; + it != mapstr.end(); + it++, offset+=bufsize ) { + memcpy(&initTable[offset], *it, tocopy > bufsize ? bufsize : tocopy); + tocopy -= bufsize; + delete [] *it; + } + tlog0<<"done."<