This patch tries to fix bug 2614. Basically, dur to bug 2007, it was
possible to create files not under change tracking that would contain
\change_inserted tags. In this case, the autor id is not meaningful
and this creates a crash.

Please test this patch on the various files that have been floating
around. 

Michael, I think this is orthogonal to your CT work, right?

JMarc

Index: src/text.C
===================================================================
--- src/text.C	(revision 13965)
+++ src/text.C	(working copy)
@@ -328,14 +328,28 @@ void readParToken(Buffer const & buf, Pa
 		int aid;
 		lyx::time_type ct;
 		is >> aid >> ct;
-		change = Change(Change::INSERTED, bp.author_map[aid], ct);
+		if (aid >= bp.author_map.size()) {
+			buf.error(ErrorItem(_("Change tracking error"),
+					    bformat(_("Unknown author index for insertion: %1$d\n"), aid),
+					    par.id(), 0, par.size()));
+			
+			change = Change(Change::UNCHANGED);
+		} else
+			change = Change(Change::INSERTED, bp.author_map[aid], ct);
 	} else if (token == "\\change_deleted") {
 		lex.eatLine();
 		std::istringstream is(lex.getString());
 		int aid;
 		lyx::time_type ct;
 		is >> aid >> ct;
-		change = Change(Change::DELETED, bp.author_map[aid], ct);
+		if (aid >= bp.author_map.size()) {
+			buf.error(ErrorItem(_("Change tracking error"),
+					    bformat(_("Unknown author index for deletion: %1$d\n"), aid),
+					    par.id(), 0, par.size()));
+			
+			change = Change(Change::UNCHANGED);
+		} else
+			change = Change(Change::DELETED, bp.author_map[aid], ct);
 	} else {
 		lex.eatLine();
 		buf.error(ErrorItem(_("Unknown token"),
Index: src/bufferparams.h
===================================================================
--- src/bufferparams.h	(revision 13965)
+++ src/bufferparams.h	(working copy)
@@ -223,7 +223,7 @@ public:
 	AuthorList const & authors() const;
 
 	/// map of the file's author IDs to buffer author IDs
-	std::vector<int> author_map;
+	std::vector<unsigned int> author_map;
 	///
 	std::string const dvips_options() const;
 	///

Reply via email to