modify BundleReader and the version read

This commit is contained in:
lvlong 2014-07-01 09:26:21 +08:00
parent 701a2b60c2
commit df7ab50062
3 changed files with 19 additions and 16 deletions

View File

@ -463,20 +463,23 @@ bool Bundle3D::loadBinary(const std::string& path)
// Read version
unsigned char ver[2];
if (_binaryReader.read(ver, 1, 2) == 2)
{
if (ver[0] != 0) {
clear();
CCLOGINFO(false, "Unsupported version: (%d, %d)", ver[0], ver[1]);
return false;
}
if (ver[1] <= 0 || ver[1] > 2) {
clear();
CCLOGINFO(false, "Unsupported version: (%d, %d)", ver[0], ver[1]);
return false;
}
if (_binaryReader.read(ver, 1, 2)!= 2){
CCLOG("Failed to read version:");
return false;
}
if (ver[0] != 0) {
clear();
CCLOGINFO(false, "Unsupported version: (%d, %d)", ver[0], ver[1]);
return false;
}
if (ver[1] <= 0 || ver[1] > 2) {
clear();
CCLOGINFO(false, "Unsupported version: (%d, %d)", ver[0], ver[1]);
return false;
}
// Read ref table size
if (_binaryReader.read(&_referenceCount, 4, 1) != 1)

View File

@ -65,7 +65,7 @@ char* BundleReader::readLine(int num,char* line)
char* p = line;
char c;
ssize_t readNum = 0;
while((c=*buffer) != 10 && readNum < (ssize_t)num && m_position<(long int)m_length)
while((c=*buffer) != 10 && readNum < (ssize_t)num && m_position < m_length)
{
*p = c;
p++;
@ -91,7 +91,7 @@ ssize_t BundleReader::length()
return m_length;
}
long int BundleReader::tell()
ssize_t BundleReader::tell()
{
if (!m_buffer)
return -1;

View File

@ -112,7 +112,7 @@ public:
bool readMatrix(float* m);
private:
long int m_position;
ssize_t m_position;
ssize_t m_length;
char* m_buffer;
};