From: H.G. Muller Date: Mon, 1 Apr 2013 18:43:36 +0000 (+0200) Subject: Fix Xaw file browser X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=321f4bd746c5269f4c630149887796293afd5249;p=xboard.git Fix Xaw file browser The 'next page' entry of the Xaw file browser contained a \177 character to keep at sorted at the bottom. This caused trouble for gettext. Now the sorting range is adapted so the 'next page' is never part of it. More seriously, the listbox fill code had a wrong cast when testing for an empty listbox on the first element, so that it only tested the low byte of the pointer, in stead of the entire pointer for NULLness. As a result the contents of the listboxes could suddenly disappear when even when it was non-empty, because the first filename was allocated at an unlucky address. --- diff --git a/dialogs.c b/dialogs.c index f32b383..a9c6414 100644 --- a/dialogs.c +++ b/dialogs.c @@ -2470,12 +2470,12 @@ ListDir (int pathFlag) ASSIGN(fileList[filePtr], s); filePtr++; } } - if(filePtr == MAXFILES-2) { ASSIGN(fileList[filePtr], _("\177 next page")); filePtr++; } + if(filePtr == MAXFILES-2) { ASSIGN(fileList[filePtr], _(" next page")); filePtr++; } FREE(folderList[folderPtr]); folderList[folderPtr] = NULL; FREE(fileList[filePtr]); fileList[filePtr] = NULL; closedir(dir); extFlag = 0; qsort((void*)folderList, folderPtr, sizeof(char*), &Comp); - extFlag = byExtension; qsort((void*)fileList, filePtr, sizeof(char*), &Comp); + extFlag = byExtension; qsort((void*)fileList, filePtr < MAXFILES-2 ? filePtr : MAXFILES-2, sizeof(char*), &Comp); } void @@ -2506,7 +2506,7 @@ Switch (int n) { if(byExtension == (n == 4)) return; extFlag = byExtension = (n == 4); - qsort((void*)fileList, filePtr, sizeof(char*), &Comp); + qsort((void*)fileList, filePtr < MAXFILES-2 ? filePtr : MAXFILES-2, sizeof(char*), &Comp); LoadListBox(&browseOptions[6], "", -1, -1); } @@ -2526,7 +2526,7 @@ SetTypeFilter (int n) void FileSelProc (int n, int sel) { - if(sel<0) return; + if(sel < 0 || fileList[sel] == NULL) return; if(sel == MAXFILES-2) { pageStart = cnt; Refresh(-1); return; } ASSIGN(fileName, fileList[sel]); if(BrowseOK(0)) PopDown(BrowserDlg); diff --git a/xaw/xoptions.c b/xaw/xoptions.c index 7f73a0b..6a193a0 100644 --- a/xaw/xoptions.c +++ b/xaw/xoptions.c @@ -201,7 +201,8 @@ LoadListBox (Option *opt, char *emptyText, int n1, int n2) { static char *dummyList[2]; dummyList[0] = emptyText; // empty listboxes tend to crash X, so display user-supplied warning string instead - XawListChange(opt->handle, *(char*)opt->target ? opt->target : dummyList, 0, 0, True); + XawListChange(opt->handle, *(char**)opt->target ? opt->target : dummyList, 0, 0, True); +//printf("listbox data = %x\n", opt->target); } int