logging-log4cxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tsunami <tsun...@126.com>
Subject there was a logic error in SocketOutputStream::write(String& str) in V0.9.7
Date Tue, 06 Dec 2005 05:48:40 GMT
I guess the writer's original purpose is:
first, write the length of the string into the opened socket.
second, if the length is greater than 0 and less than 1024 , write directly; 
   if the length is over than 1024, truncating the string's length to 1024. 
But there was a wrong here:
let's surpose that if we want to write a string with 2048 chars,this function 
will write a unsigned int with "2048" into socket first, then write 1024 chars 
into socket.
there was another wrong: the string written into the socket was not terminated 
with null, this will lead to error In SocketInputStream::read(String& str)

I suggest the function would be modified like this:
void SocketOutputStream::write(const String& value)
	String::size_type size;
	size = value.size();

	if (size > 1024) size = 1024; // modified by tsunami 2005-12-4
	write(&size, sizeof(String::size_type)); // modified by tsunami 2005-
	if (size > 0)
		write(value.substr(0, size).c_str(), size * sizeof(TCHAR)); // 
set value[size-1] = '\0'. modified by tsunami


View raw message