aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/PerLine.cxx
diff options
context:
space:
mode:
authornyamatongwe <unknown>2012-03-27 10:17:29 +1100
committernyamatongwe <unknown>2012-03-27 10:17:29 +1100
commitd716ac0173cc608a61503ada0f907637285a5d8d (patch)
tree5f7e95dcbe5d59ce74614cece3ab747cbc0e243e /src/PerLine.cxx
parent277230dd1ecc8a0f4a359160ad13a68b84dc9e9e (diff)
downloadscintilla-mirror-d716ac0173cc608a61503ada0f907637285a5d8d.tar.gz
Protect against modifying annotations with a negative line number or a line
number after the document end.
Diffstat (limited to 'src/PerLine.cxx')
-rw-r--r--src/PerLine.cxx50
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;