From 14239008e19b29a836b10fd1c56df03d472a52e1 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Wed, 4 May 2011 13:53:05 +0200 Subject: [PATCH] Lift limitation of text length in generic dialog XB All string options should now point to allocated memory, as strdup / free is consistently used on them. This is OK for values received from ParseArgs, but for non-arg intermediate variables that must receive strg values, such as in the comment and tags popups, strdup has to be used to initialize those. --- xoptions.c | 13 +++++++++---- 1 files changed, 9 insertions(+), 4 deletions(-) diff --git a/xoptions.c b/xoptions.c index 598019e..0c1e4c9 100644 --- a/xoptions.c +++ b/xoptions.c @@ -1243,7 +1243,10 @@ void GenericReadout(int selected) if(currentCps) { snprintf(buf, MSG_SIZ, "option %s=%s\n", currentOption[i].name, val); SendToProgram(buf, currentCps); - } else *dest = currentOption[i].name + 100; // option gets to point to private storage; + } else { + if(*dest) free(*dest); + *dest = malloc(strlen(val)+1); + } safeStrCpy(*dest, val, MSG_SIZ - (*dest - currentOption[i].name)); // copy text there } break; @@ -1880,7 +1883,7 @@ void NewCommentPopup(char *title, char *text, int index) XtSetArg(args[0], XtNstring, text); XtSetValues(commentOptions[0].handle, args, 1); } - commentText = text; + if(commentText) free(commentText); commentText = strdup(text); commentIndex = index; MarkMenu("menuView.Show Comments", 1); if(GenericPopUp(commentOptions, title, 1)) @@ -1918,7 +1921,7 @@ void NewTagsPopup(char *text, char *msg) XtSetArg(args[0], XtNstring, text); XtSetValues(tagsOptions[1].handle, args, 1); } - tagsText = text; + if(tagsText) free(tagsText); tagsText = strdup(text); tagsOptions[0].textValue = msg; MarkMenu("menuView.Show Tags", 2); GenericPopUp(tagsOptions, _("Tags"), 2); @@ -2055,9 +2058,11 @@ void LoadEngineProc(w, event, prms, nprms) Cardinal *nprms; { isUCI = addToList = storeVariant = v1 = False; hasBook = True; // defaults - engineDir = nickName = params = ""; if(engineChoice) free(engineChoice); engineChoice = strdup(engineNr[0]); if(engineLine) free(engineLine); engineLine = strdup(""); + if(engineDir) free(engineDir); engineDir = strdup(""); + if(nickName) free(nickName); nickName = strdup(""); + if(params) free(params); params = strdup(""); NamesToList(firstChessProgramNames, engineList, engineMnemonic); GenericPopUp(installOptions, _("Load engine"), 0); } -- 1.7.0.4