diff options
Diffstat (limited to 'src/PerLine.cxx')
| -rw-r--r-- | src/PerLine.cxx | 50 | 
1 files changed, 26 insertions, 24 deletions
| diff --git a/src/PerLine.cxx b/src/PerLine.cxx index 7e716ccc0..0bdb60254 100644 --- a/src/PerLine.cxx +++ b/src/PerLine.cxx @@ -397,28 +397,28 @@ bool LineAnnotation::AnySet() const {  }  bool LineAnnotation::MultipleStyles(int line) const { -	if (annotations.Length() && (line < annotations.Length()) && annotations[line]) +	if (annotations.Length() && (line >= 0) && (line < annotations.Length()) && annotations[line])  		return reinterpret_cast<AnnotationHeader *>(annotations[line])->style == IndividualStyles;  	else  		return 0;  }  int LineAnnotation::Style(int line) { -	if (annotations.Length() && (line < annotations.Length()) && annotations[line]) +	if (annotations.Length() && (line >= 0) && (line < annotations.Length()) && annotations[line])  		return reinterpret_cast<AnnotationHeader *>(annotations[line])->style;  	else  		return 0;  }  const char *LineAnnotation::Text(int line) const { -	if (annotations.Length() && (line < annotations.Length()) && annotations[line]) +	if (annotations.Length() && (line >= 0) && (line < annotations.Length()) && annotations[line])  		return annotations[line]+sizeof(AnnotationHeader);  	else  		return 0;  }  const unsigned char *LineAnnotation::Styles(int line) const { -	if (annotations.Length() && (line < annotations.Length()) && annotations[line] && MultipleStyles(line)) +	if (annotations.Length() && (line >= 0) && (line < annotations.Length()) && annotations[line] && MultipleStyles(line))  		return reinterpret_cast<unsigned char *>(annotations[line] + sizeof(AnnotationHeader) + Length(line));  	else  		return 0; @@ -432,7 +432,7 @@ static char *AllocateAnnotation(int length, int style) {  }  void LineAnnotation::SetText(int line, const char *text) { -	if (text) { +	if (text && (line >= 0)) {  		annotations.EnsureLength(line+1);  		int style = Style(line);  		if (annotations[line]) { @@ -445,7 +445,7 @@ void LineAnnotation::SetText(int line, const char *text) {  		pah->lines = static_cast<short>(NumberLines(text));  		memcpy(annotations[line]+sizeof(AnnotationHeader), text, pah->length);  	} else { -		if (annotations.Length() && (line < annotations.Length()) && annotations[line]) { +		if (annotations.Length() && (line >= 0) && (line < annotations.Length()) && annotations[line]) {  			delete []annotations[line];  			annotations[line] = 0;  		} @@ -469,35 +469,37 @@ void LineAnnotation::SetStyle(int line, int style) {  }  void LineAnnotation::SetStyles(int line, const unsigned char *styles) { -	annotations.EnsureLength(line+1); -	if (!annotations[line]) { -		annotations[line] = AllocateAnnotation(0, IndividualStyles); -	} else { -		AnnotationHeader *pahSource = reinterpret_cast<AnnotationHeader *>(annotations[line]); -		if (pahSource->style != IndividualStyles) { -			char *allocation = AllocateAnnotation(pahSource->length, IndividualStyles); -			AnnotationHeader *pahAlloc = reinterpret_cast<AnnotationHeader *>(allocation); -			pahAlloc->length = pahSource->length; -			pahAlloc->lines = pahSource->lines; -			memcpy(allocation + sizeof(AnnotationHeader), annotations[line] + sizeof(AnnotationHeader), pahSource->length); -			delete []annotations[line]; -			annotations[line] = allocation; +	if (line >= 0) { +		annotations.EnsureLength(line+1); +		if (!annotations[line]) { +			annotations[line] = AllocateAnnotation(0, IndividualStyles); +		} else { +			AnnotationHeader *pahSource = reinterpret_cast<AnnotationHeader *>(annotations[line]); +			if (pahSource->style != IndividualStyles) { +				char *allocation = AllocateAnnotation(pahSource->length, IndividualStyles); +				AnnotationHeader *pahAlloc = reinterpret_cast<AnnotationHeader *>(allocation); +				pahAlloc->length = pahSource->length; +				pahAlloc->lines = pahSource->lines; +				memcpy(allocation + sizeof(AnnotationHeader), annotations[line] + sizeof(AnnotationHeader), pahSource->length); +				delete []annotations[line]; +				annotations[line] = allocation; +			}  		} +		AnnotationHeader *pah = reinterpret_cast<AnnotationHeader *>(annotations[line]); +		pah->style = IndividualStyles; +		memcpy(annotations[line] + sizeof(AnnotationHeader) + pah->length, styles, pah->length);  	} -	AnnotationHeader *pah = reinterpret_cast<AnnotationHeader *>(annotations[line]); -	pah->style = IndividualStyles; -	memcpy(annotations[line] + sizeof(AnnotationHeader) + pah->length, styles, pah->length);  }  int LineAnnotation::Length(int line) const { -	if (annotations.Length() && (line < annotations.Length()) && annotations[line]) +	if (annotations.Length() && (line >= 0) && (line < annotations.Length()) && annotations[line])  		return reinterpret_cast<AnnotationHeader *>(annotations[line])->length;  	else  		return 0;  }  int LineAnnotation::Lines(int line) const { -	if (annotations.Length() && (line < annotations.Length()) && annotations[line]) +	if (annotations.Length() && (line >= 0) && (line < annotations.Length()) && annotations[line])  		return reinterpret_cast<AnnotationHeader *>(annotations[line])->lines;  	else  		return 0; | 
