See http://bugzilla.lyx.org/show_bug.cgi?id=2086. The problem is that the 
pointer 'codec' can be 0, and that is not checked before dereferencing.
The patch is based on the one sent by Andreas (but without the codec for 
the "C" locale, because I don't know if that is correct), + some 
whitespace corrections.
It seems that encode() is called with an empty encoding. I don't know why, 
so this patch does not cure the root of the problem, but symptoms.
I'd apply it anyway, since a 0 pointer can also occur for unknown 
encodings.

OK to apply?


Georg
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/frontends/qt2/ChangeLog lyx-1.4-cvs/src/frontends/qt2/ChangeLog
--- lyx-1.4-clean/src/frontends/qt2/ChangeLog	2005-10-08 10:43:51.000000000 +0200
+++ lyx-1.4-cvs/src/frontends/qt2/ChangeLog	2005-10-16 17:27:09.016876088 +0200
@@ -1,3 +1,7 @@
+2005-10-16  Georg Baum  <[EMAIL PROTECTED]>
+
+	* QLyXKeySym.C (initEncodings): prevent crash when no codec found
+
 2005-10-07  Martin Vermeer  <[EMAIL PROTECTED]>
 
 	* QContentPane.C (QContentPane): make times 50 msec instead of 25,
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/frontends/qt2/QLyXKeySym.C lyx-1.4-cvs/src/frontends/qt2/QLyXKeySym.C
--- lyx-1.4-clean/src/frontends/qt2/QLyXKeySym.C	2005-07-17 14:57:28.000000000 +0200
+++ lyx-1.4-cvs/src/frontends/qt2/QLyXKeySym.C	2005-10-13 14:33:18.000000000 +0200
@@ -45,20 +45,23 @@ char const encode(string const & encodin
 
 	EncodingMap::const_iterator cit = encoding_map.find(encoding);
 	if (cit == encoding_map.end()) {
-		if (lyxerr.debugging())
-			lyxerr[Debug::KEY] << "Unrecognised encoding "
-				<< encoding << endl;
+		lyxerr[Debug::KEY] << "Unrecognised encoding '" << encoding
+		                   << "'." << endl;
 		codec = encoding_map.find("")->second;
 	} else {
 		codec = cit->second;
 	}
 
-	if (lyxerr.debugging())
-		lyxerr[Debug::KEY] << "Using codec " << fromqstr(codec->name()) << endl;
+	if (!codec) {
+		lyxerr[Debug::KEY] << "No codec for encoding '" << encoding
+		                   << "' found." << endl;
+		return 0;
+	}
+
+	lyxerr[Debug::KEY] << "Using codec " << fromqstr(codec->name()) << endl;
 
 	if (!codec->canEncode(str)) {
-		if (lyxerr.debugging())
-			lyxerr[Debug::KEY] << "Oof. Can't encode the text !" << endl;
+		lyxerr[Debug::KEY] << "Oof. Can't encode the text !" << endl;
 		return 0;
 	}
 
@@ -84,7 +87,7 @@ void initEncodings()
 				s = "C";
 		}
 	}
-	
+
 	if (s.find("UTF") != string::npos || s.find("utf") != string::npos) 
 	//if (contains(c, "UTF") || contains(c, "utf"))
 		lyxerr << "Warning: this system's locale uses Unicode." << endl;
@@ -112,17 +116,16 @@ void initEncodings()
 	encoding_map["pt154"] = 0;
 
 	// There are lots more codecs in Qt too ...
-	
+
 	// when no document open
 	// use the appropriate encoding for the system language
 	lyxerr << "Language code:" << s << endl;
 	for (Languages::const_iterator it=languages.begin(); it != languages.end(); ++it) {
 		//lyxerr << it->second.code() << ":" << it->second.encodingStr() << ":" << it->second.encoding() << endl;
-		if (it->second.code() == s)
-			{
-				s = it->second.encodingStr();
-				break;
-			}
+		if (it->second.code() == s) {
+			s = it->second.encodingStr();
+			break;
+		}
 	}
 	lyxerr << "Setting new locale for Qt:" << s << endl;
 	QTextCodec * defaultCodec = encoding_map[s];

Reply via email to