sources/network/bytestream.cpp

changeset 99
f9f73eeba3b7
parent 98
4f0f0b1b8e0b
child 109
e4966d7e615d
equal deleted inserted replaced
98:4f0f0b1b8e0b 99:f9f73eeba3b7
190 static char buffer[MAX_NETWORK_STRING]; 190 static char buffer[MAX_NETWORK_STRING];
191 unsigned char* stringEnd; 191 unsigned char* stringEnd;
192 unsigned char* stringBegin = m_cursor; 192 unsigned char* stringBegin = m_cursor;
193 unsigned char* end = m_data + allocated_size(); 193 unsigned char* end = m_data + allocated_size();
194 194
195 // where's the end of the string? 195 // Where's the end of the string?
196 for (stringEnd = m_cursor; *stringEnd != '\0'; ++stringEnd) 196 for (stringEnd = m_cursor; *stringEnd != '\0'; ++stringEnd)
197 { 197 {
198 if (stringEnd == end) 198 if (stringEnd == end)
199 // past the end of the buffer! Argh! 199 {
200 throw IOError ("unterminated string in packet"); 200 // Past the end of the buffer
201 throw IOError ("unterminated or too long string in packet");
202 }
201 } 203 }
202 204
205 unsigned int length = stringEnd - m_cursor;
203 m_cursor = stringEnd + 1; 206 m_cursor = stringEnd + 1;
204 unsigned int length = stringEnd - m_cursor;
205
206 // ensure we won't write past the buffer (note: we still moved
207 // past the excess bytes in the above statement, those are ignored)
208 if (length >= MAX_NETWORK_STRING)
209 length = MAX_NETWORK_STRING - 1;
210
211 memcpy (buffer, stringBegin, length); 207 memcpy (buffer, stringBegin, length);
212 buffer[length] = '\0'; 208 buffer[length] = '\0';
213 return String (buffer); 209 return String (buffer);
214 } 210 }
215 211

mercurial