/*
-Copyright (c) 2006-2010, John Hurst
+Copyright (c) 2006-2011, John Hurst
All rights reserved.
Redistribution and use in source and binary forms, with or without
return true;
}
- inline bool WriteString(const std::string& str)
- {
- if ( ! WriteUi32BE(str.length()) ) return false;
- if ( ! WriteRaw((const byte_t*)str.c_str(), str.length()) ) return false;
+ inline bool WriteString(const std::string& str) {
+ ui32_t len = static_cast<ui32_t>(str.length());
+ if ( ! WriteUi32BE(len) ) return false;
+ if ( ! WriteRaw((const byte_t*)str.c_str(), len) ) return false;
return true;
}
- };
+ };
//
class MemIOReader
inline bool ReadString(std::string& str)
{
- ui32_t str_length;
+ ui32_t str_length = 0;
if ( ! ReadUi32BE(&str_length) ) return false;
- if ( ( m_size + str_length ) > m_capacity ) return false;
- str.assign((const char*)CurrentData(), str_length);
- if ( ! SkipOffset(str_length) ) return false;
+
+ if ( str_length > 0 )
+ {
+ if ( ( m_size + str_length ) > m_capacity ) return false;
+ str.assign((const char*)CurrentData(), str_length);
+ if ( ! SkipOffset(str_length) ) return false;
+ }
+
return true;
}
};