Fix segfault on single-line help text
[xboard.git] / dialogs.c
index ca9f71c..ece6c40 100644 (file)
--- a/dialogs.c
+++ b/dialogs.c
@@ -1310,10 +1310,12 @@ char *icsText;
 #define HISTORY_SIZE 64
 static char *history[HISTORY_SIZE];
 static int histIn = 0, histP = 0;
+static Boolean noEcho;
 
 static void
 SaveInHistory (char *cmd)
 {
+  if(noEcho) return; // do not save password!
   if (history[histIn] != NULL) {
     free(history[histIn]);
     history[histIn] = NULL;
@@ -2156,8 +2158,6 @@ ConsoleAutoPopUp (char *buf)
        } else PopUpMoveDialog(*buf);
 }
 
-static Boolean noEcho;
-
 void
 EchoOn ()
 {
@@ -2458,13 +2458,14 @@ ReadLine (FILE *f)
 void
 GetHelpText (FILE *f, char *name)
 {
-    char *line, buf[MSG_SIZ], text[10000], *p = text, *q = text;
+    char *line, buf[MSG_SIZ], title[MSG_SIZ], text[10000], *p = text, *q = text;
     int len, cnt = 0;
     snprintf(buf, MSG_SIZ, ".B %s", name);
     len = strlen(buf);
-    for(len=1; buf[len] == ' ' || isalpha(buf[len]) || isdigit(buf[len]); len++);
+    for(len=1; buf[len] == ' ' || buf[len] == '-' || isalpha(buf[len]) || isdigit(buf[len]); len++);
     buf[len] = NULLCHAR;
     while(buf[--len] == ' ') buf[len] = NULLCHAR;
+    snprintf(title, MSG_SIZ, "Help on '%s'", buf+3);
     while((line = ReadLine(f))) {
        if(!strncmp(line, buf, len) && (strncmp(line, ".SS ", 4) || strncmp(line+4, buf+3, len-3))) {
            while((line = ReadLine(f)) && (cnt == 0 || strncmp(line, ".B ", 3))) {
@@ -2479,7 +2480,7 @@ GetHelpText (FILE *f, char *name)
                if(p - text > 9900) break;
            }
            *p = NULLCHAR;
-           DisplayNote(text);
+           ErrorPopUp(title, text, FALSE);
            return;
        }
     }
@@ -2892,6 +2893,7 @@ static char *Extensions[] = {
 ".trn",
 ".bin",
 ".wav",
+".png",
 ".ini",
 ".log",
 "",