[PATCH 4/5] editor: Improve checks on delete add asserts

Jan Arne Petersen jpetersen at openismus.com
Thu May 30 04:57:04 PDT 2013


From: Jan Arne Petersen <jpetersen at openismus.com>

Signed-off-by: Jan Arne Petersen <jpetersen at openismus.com>
---
 clients/editor.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/clients/editor.c b/clients/editor.c
index 35f6d08..cd24f6a 100644
--- a/clients/editor.c
+++ b/clients/editor.c
@@ -214,7 +214,8 @@ text_input_delete_surrounding_text(void *data,
 		return;
 	}
 
-	if (entry->pending_commit.delete_index + length > text_length) {
+	if (length > text_length ||
+	    entry->pending_commit.delete_index + length > text_length) {
 		fprintf(stderr, "Invalid length %d\n", length);
 		entry->pending_commit.delete_length = 0;
 		return;
@@ -837,6 +838,9 @@ text_entry_delete_text(struct text_entry *entry,
 {
 	uint32_t l;
 
+	assert(index <= strlen(entry->text));
+	assert(index + length <= strlen(entry->text));
+	assert(index + length >= length);
 
 	l = strlen(entry->text + index + length);
 	memmove(entry->text + index,
-- 
1.8.1.4



More information about the wayland-devel mailing list