changeset 2015:db8ec238cd2c

Fix segfault when spell checking is enabled and spell_lang is not set. This patch fixes issue #93.
author Mikael Berthe <mikael@lilotux.net>
date Wed, 04 Jul 2012 21:15:43 +0200
parents 99db5d4ed047
children e9b6e168a45e
files mcabber/mcabber/screen.c
diffstat 1 files changed, 20 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/mcabber/screen.c	Thu Mar 01 20:18:00 2012 +0100
+++ b/mcabber/mcabber/screen.c	Wed Jul 04 21:15:43 2012 +0200
@@ -43,10 +43,10 @@
 
 #ifdef WITH_ENCHANT
 # include <enchant.h>
-#endif
-
-#ifdef WITH_ASPELL
-# include <aspell.h>
+#else
+# ifdef WITH_ASPELL
+#  include <aspell.h>
+# endif
 #endif
 
 #include "screen.h"
@@ -4365,9 +4365,6 @@
      spell_checker = NULL;
      spell_broker = NULL;
   }
-
-  spell_broker = enchant_broker_init();
-  spell_checker = enchant_broker_request_dict(spell_broker, spell_lang);
 #endif
 #ifdef WITH_ASPELL
   if (spell_checker) {
@@ -4376,9 +4373,23 @@
     spell_checker = NULL;
     spell_config = NULL;
   }
-
+#endif
+
+  if (!spell_lang) { // Cannot initialize: language not specified
+    scr_LogPrint(LPRINT_LOGNORM, "Error: Cannot initialize spell checker, language not specified.");
+    scr_LogPrint(LPRINT_LOGNORM, "Please set the 'spell_lang' variable.");
+    return;
+  }
+
+#ifdef WITH_ENCHANT
+  spell_broker = enchant_broker_init();
+  spell_checker = enchant_broker_request_dict(spell_broker, spell_lang);
+#endif
+
+#ifdef WITH_ASPELL
   spell_config = new_aspell_config();
-  aspell_config_replace(spell_config, "encoding", spell_encoding);
+  if (spell_encoding)
+    aspell_config_replace(spell_config, "encoding", spell_encoding);
   aspell_config_replace(spell_config, "lang", spell_lang);
   possible_err = new_aspell_speller(spell_config);