merge JSON-172 "hang in ./server/logger.cc: void wrapLongLine" into default Release_2.1.0-RC16
authorRoker <roker@pep-project.org>
Thu, 21 Jan 2021 10:12:52 +0100
changeset 11295380ce502b28
parent 1126 0ddfedaa0578
parent 1128 c6b56421d08c
child 1130 28def6c53954
merge JSON-172 "hang in ./server/logger.cc: void wrapLongLine" into default
     1.1 --- a/server/logger.cc	Tue Jan 12 12:45:03 2021 +0100
     1.2 +++ b/server/logger.cc	Thu Jan 21 10:12:52 2021 +0100
     1.3 @@ -186,13 +186,26 @@
     1.4  			end += delta;
     1.5  			ofs += delta;
     1.6  			
     1.7 -			if(end != oneline.end())
     1.8 +			if(end != oneline.end()) // we're not yet at the end, so we wrap the line here...
     1.9  			{
    1.10 -				while( (uint8_t(*end) >= 0x80) && (end>begin) )
    1.11 +				unsigned sequence_length = 0;
    1.12 +				
    1.13 +				// avoid split within a UTF-8 multibyte sequence.
    1.14 +				// Therefore move backwards until we point to the start octet of an UTF-8 sequence.
    1.15 +				while( (uint8_t(*end) >= 0x80) && (uint8_t(*end)<0xC0) && (end>begin) && (sequence_length<8))
    1.16  				{
    1.17  					// rewind
    1.18  					--end;
    1.19  					--ofs;
    1.20 +					++sequence_length;
    1.21 +				}
    1.22 +				
    1.23 +				if(sequence_length>=8) // can never happen on valid UTF-8 strings
    1.24 +				{
    1.25 +					// the input is not valid UTF-8, so undo the rewind from above
    1.26 +					// and write out whatever the string contains. :-/
    1.27 +					end += sequence_length;
    1.28 +					ofs += sequence_length;
    1.29  				}
    1.30  			}
    1.31  			
     2.1 --- a/server/unittest_logger.cc	Tue Jan 12 12:45:03 2021 +0100
     2.2 +++ b/server/unittest_logger.cc	Thu Jan 21 10:12:52 2021 +0100
     2.3 @@ -3,14 +3,24 @@
     2.4  
     2.5  namespace
     2.6  {
     2.7 +	const std::string nonAscii = "ۤ";
     2.8 +
     2.9  	std::string longstring(unsigned length)
    2.10  	{
    2.11  		std::string s;
    2.12  		s.reserve(length);
    2.13 -		for(unsigned u=0; u<length; ++u)
    2.14 +		unsigned u=0;
    2.15 +		for(; u+nonAscii.size()<=length; u+=nonAscii.size())
    2.16 +		{
    2.17 +			s += nonAscii;
    2.18 +		}
    2.19 +		
    2.20 +		for(u=s.size(); u<length; ++u)
    2.21  		{
    2.22  			s += char( (u%94) + '!' );
    2.23  		}
    2.24 +		
    2.25 +		
    2.26  		return s;
    2.27  	}
    2.28  }
    2.29 @@ -58,12 +68,12 @@
    2.30  	Logger L("LongLine");
    2.31  	
    2.32  	char buffer[64];
    2.33 -	double length = 10.0;
    2.34 +	double length = 0;
    2.35  	while(length < 4444)
    2.36  	{
    2.37  		snprintf(buffer, 63, "Length %d octets: ", int(length));
    2.38  		L.notice( buffer + longstring(length));
    2.39 -		length *= 1.71;
    2.40 +		++length;
    2.41  	}
    2.42  
    2.43  }