security fix: replaced strcpy with safeStrCpy from backend.c
[xboard.git] / xhistory.c
index 6f94e62..fe48893 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * xhistory.c -- Move list window, part of X front end for XBoard
  *
- * Copyright 2000,2009 Free Software Foundation, Inc.
+ * Copyright 2000, 2009, 2010 Free Software Foundation, Inc.
  * ------------------------------------------------------------------------
  *
  * GNU XBoard is free software: you can redistribute it and/or modify
@@ -78,7 +78,7 @@ extern char *getenv();
 
 #define _LL_ 100
 
-extern Widget formWidget, shellWidget, boardWidget, menuBarWidget;
+extern Widget formWidget, shellWidget, boardWidget, menuBarWidget, historyShell;
 extern Display *xDisplay;
 extern int squareSize;
 extern Pixmap xMarkPixmap;
@@ -94,7 +94,7 @@ struct History{
 struct History *hist=0;
 String dots=" ... ";
 Position gameHistoryX, gameHistoryY;
-Dimension gameHistoryW;
+Dimension gameHistoryW, gameHistoryH;
 
 void
 HistoryPopDown(w, client_data, call_data)
@@ -104,6 +104,19 @@ HistoryPopDown(w, client_data, call_data)
   Arg args[16];
   int j;
   if(hist) {
+
+    // [HGM] remember old position
+    j = 0;
+    XtSetArg(args[j], XtNx, &gameHistoryX);  j++;
+    XtSetArg(args[j], XtNy, &gameHistoryY);  j++;
+    XtSetArg(args[j], XtNwidth, &gameHistoryW);  j++;
+    XtSetArg(args[j], XtNheight, &gameHistoryH);  j++;
+    XtGetValues(hist->sh, args, j);
+    wpMoveHistory.x = gameHistoryX - 4;
+    wpMoveHistory.y = gameHistoryY - 23;
+    wpMoveHistory.width  = gameHistoryW;
+    wpMoveHistory.height = gameHistoryH;
+
     XtPopdown(hist->sh);
     hist->Up=False;
   }
@@ -220,10 +233,10 @@ void HistorySet(char movelist[][2*MOVE_LEN],int first,int last,int current){
            strncpy(hist->white[i/2+1], movelist[i], p-movelist[i]);
            hist->white[i/2+1][p-movelist[i]] = NULLCHAR;
          } else {
-           strcpy(hist->white[i/2+1],movelist[i]);
+           safeStrCpy(hist->white[i/2+1],movelist[i], sizeof(hist->white[i/2+1])/sizeof(hist->white[i/2+1][0]));
          }
        } else {
-         strcpy(hist->white[i/2+1],dots);
+         safeStrCpy(hist->white[i/2+1],dots, sizeof(hist->white[i/2+1])/sizeof(hist->white[i/2+1][0]));
        }
       } else {
        if(movelist[i][0]) {
@@ -232,14 +245,14 @@ void HistorySet(char movelist[][2*MOVE_LEN],int first,int last,int current){
            strncpy(hist->black[i/2+1], movelist[i], p-movelist[i]);
            hist->black[i/2+1][p-movelist[i]] = NULLCHAR;
          } else {
-           strcpy(hist->black[i/2+1],movelist[i]);
+           safeStrCpy(hist->black[i/2+1],movelist[i], sizeof(hist->black[i/2+1])/sizeof(hist->black[i/2+1][0]));
          }
        } else {
-         strcpy(hist->black[i/2+1],"");
+         safeStrCpy(hist->black[i/2+1],"", sizeof(hist->black[i/2+1])/sizeof(hist->black[i/2+1][0]));
        }
       }
     }
-    strcpy(hist->black[last/2+1],"");
+    safeStrCpy(hist->black[last/2+1],"", sizeof(hist->black[last/2+1])/sizeof(hist->black[last/2+1][0]));
     b=first/2;
     m=(last+3)/2-b;
     XawFormDoLayout(hist->vbox, False);
@@ -262,6 +275,7 @@ void HistorySet(char movelist[][2*MOVE_LEN],int first,int last,int current){
       else XawListUnhighlight(hist->mvb);
     }
   }
+  EvalGraphSet( first, last, current, pvInfoList ); // piggy-backed
 }
 
 Widget HistoryCreate()
@@ -283,11 +297,11 @@ Widget HistoryCreate()
     XtSetArg(args[j], XtNresizable, True);  j++;
     XtSetArg(args[j], XtNallowShellResize, True);  j++;
 #if TOPLEVEL
-    hist->sh =
+    hist->sh = historyShell =
       XtCreatePopupShell(_("Move list"), topLevelShellWidgetClass,
                         shellWidget, args, j);
 #else
-    hist->sh =
+    hist->sh = historyShell =
       XtCreatePopupShell(_("Move list"), transientShellWidgetClass,
                         shellWidget, args, j);
 #endif
@@ -304,10 +318,8 @@ Widget HistoryCreate()
 
     form =
       XtCreateManagedWidget("form", formWidgetClass, layout, args, j);
-     j=0;
 
     j = 0;
-
     XtSetArg(args[j], XtNtop, XtChainTop);  j++;
     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
@@ -392,20 +404,26 @@ Widget HistoryCreate()
     CatchDeleteWindow(hist->sh, "HistoryPopDown");
 
     for(i=1;i<hist->aNr;i++){
-      strcpy(hist->white[i],dots);
-      strcpy(hist->black[i],"");
+      safeStrCpy(hist->white[i],dots, sizeof(hist->white[i])/sizeof(hist->white[i][0]));
+      safeStrCpy(hist->black[i],"", sizeof(hist->black[i])/sizeof(hist->black[i][0]));
      }
 
+    if(wpMoveHistory.width > 0) {
+      gameHistoryW = wpMoveHistory.width;
+      gameHistoryH = wpMoveHistory.height;
+      gameHistoryX = wpMoveHistory.x;
+      gameHistoryY = wpMoveHistory.y;
+    }
+
   // [HGM] restore old position
+  if(gameHistoryW > 0) {
   j = 0;
-  XtSetArg(args[j], XtNx, &gameHistoryX);  j++;
-  XtSetArg(args[j], XtNy, &gameHistoryY);  j++;
-  XtSetArg(args[j], XtNwidth, &gameHistoryW);  j++;
-  XtGetValues(shellWidget, args, j);
-  j = 0;
-  XtSetArg(args[j], XtNx, gameHistoryX + gameHistoryW);  j++;
+    XtSetArg(args[j], XtNx, gameHistoryX);  j++;
   XtSetArg(args[j], XtNy, gameHistoryY);  j++;
+    XtSetArg(args[j], XtNwidth, gameHistoryW);  j++;
+    XtSetArg(args[j], XtNheight, gameHistoryH);  j++;
   XtSetValues(hist->sh, args, j);
+  }
     XtRealizeWidget(hist->sh);
 
     return hist->sh;
@@ -447,3 +465,8 @@ HistoryShowProc(w, event, prms, nprms)
   ToNrEvent(currentMove);
 }
 
+Boolean
+MoveHistoryIsUp()
+{
+  return hist && hist->Up;
+}