From Bugzilla Helper: User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.7) Gecko/20011228 Description of problem: 1. newt library have a lot of bugs in code (see patch in descriptions) for example your define one variable two times 2. library don't work in the simple example (like in ntsysv, but with labels instead checkboxes, see program in the steps) Version-Release number of selected component (if applicable): How reproducible: Always Steps to Reproduce: Please run next code to see segmentation fault:#include <ctype.h> =---------------------------------- #include <dirent.h> #include <errno.h> #include <newt.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/stat.h> #include <unistd.h> static int servicesWindow() { newtComponent label, subform, ok, cancel; newtComponent *checkboxes, form, curr, blank; newtComponent sb = NULL; newtGrid grid, subgrid; struct newtExitStruct ex; char *states; int i; form = newtForm(NULL, NULL, 0); grid = newtCreateGrid(3, 3); { subgrid = newtCreateGrid(2, 1); sb = newtVerticalScrollbar(-1, -1, 8, NEWT_COLORSET_CHECKBOX, NEWT_COLORSET_ACTCHECKBOX); newtFormAddComponent(form,sb); subform = newtForm(sb, NULL, 0); newtFormSetHeight(subform, 8); newtFormAddComponent(form,subform); checkboxes = (newtComponent *)alloca(sizeof(*checkboxes) * 20); states = (char *)alloca(sizeof(*states) * 20); for (i = 0; i < 20; i++) { checkboxes[i] = newtLabel(-1, i, "test"); newtFormAddComponent(subform, checkboxes[i]); } newtGridSetField(subgrid, 0, 0, NEWT_GRID_COMPONENT,subform, 0, 0, 0, 0, NEWT_ANCHOR_RIGHT, 0); newtGridSetField(subgrid, 1, 0, NEWT_GRID_COMPONENT,sb, 0, 0, 0, 0, NEWT_ANCHOR_RIGHT, 0); } newtGridSetField(grid, 0, 2, NEWT_GRID_SUBGRID, subgrid, 0, 0, 0, 0, 0,NEWT_GRID_FLAG_GROWX); ok=newtButton(-1, -1, "ok"); newtFormAddComponent(form,ok); newtGridSetField(grid, 0, 1, NEWT_GRID_COMPONENT,ok, 0, 0, 0, 0, NEWT_ANCHOR_RIGHT, 0); newtGridWrappedWindow(grid, "Services"); newtFormRun(form,&ex); newtGridFree(grid, 1); newtPopWindow(); newtFormDestroy(form); return 0; } int main(int argc, const char ** argv) { newtInit(); newtCls(); servicesWindow(); newtFinished(); } --------------------------------------------- This works well with checkboxes and segfaults with labels (code from ntsysv) Actual Results: segmentation fault Expected Results: segmentation fault Additional info: You can apply patch below to fix some bugs, but scrolling don't work in the scrollable area with labels (and works with checkboxes and entries) ---------------- diff -Naur newt-0.50.34.orig/form.c newt-0.50.34/form.c --- newt-0.50.34.orig/form.c Tue Jan 29 16:23:06 2002 +++ newt-0.50.34/form.c Tue Jan 29 16:28:27 2002 @@ -484,6 +484,7 @@ newtComponent newtFormGetCurrent(newtComponent co) { struct form * form = co->data; + if (form->currComp==-1) return 0; return form->elements[form->currComp].co; } @@ -625,8 +626,7 @@ er.result = ER_IGNORED; if (!form->numComps) return er; - - subco = form->elements[form->currComp].co; + if (form->currComp == -1) return er; switch (ev.when) { case EV_EARLY: diff -Naur newt-0.50.34.orig/windows.c newt-0.50.34/windows.c --- newt-0.50.34.orig/windows.c Tue Jan 23 09:27:38 2001 +++ newt-0.50.34/windows.c Tue Jan 29 17:29:47 2002 @@ -131,15 +131,14 @@ return 0; } -/* only supports up to 50 buttons -- shucks! */ int newtWinMenu(char * title, char * text, int suggestedWidth, int flexDown, int flexUp, int maxListHeight, char ** items, int * listItem, char * button1, ...) { newtComponent textbox, listbox, result, form; va_list args; - newtComponent buttons[50]; + newtComponent *buttons = 0; newtGrid grid, buttonBar; - int numButtons; + size_t totalButtons = 0, numButtons = 0; int i, rc; int needScroll; char * buttonName; @@ -159,15 +158,16 @@ newtListboxSetCurrent(listbox, *listItem); - buttonName = button1, numButtons = 0; va_start(args, button1); - while (buttonName) { - buttons[numButtons] = newtButton(-1, -1, buttonName); - numButtons++; - buttonName = va_arg(args, char *); - } + for (buttonName = button1; buttonName; buttonName = va_arg(args, char *)) + ++totalButtons; + va_end(args); - va_end(button1); + buttons = (newtComponent *)alloca(sizeof(newtComponent*)*(totalButtons)); + va_start(args, button1); + for (buttonName = button1; buttonName; buttonName = va_arg(args, char *)) + buttons[numButtons++] = newtButton(-1, -1, buttonName); + va_end(args); buttonBar = newtCreateGrid(numButtons, 1); for (i = 0; i < numButtons; i++) { @@ -199,15 +199,14 @@ return rc; } -/* only supports up to 50 buttons and entries -- shucks! */ int newtWinEntries(char * title, char * text, int suggestedWidth, int flexDown, int flexUp, int dataWidth, struct newtWinEntry * items, char * button1, ...) { - newtComponent buttons[50], result, form, textw; + newtComponent *buttons, result, form, textw; newtGrid grid, buttonBar, subgrid; int numItems; int rc, i; - int numButtons; + int numButtons = 0,totalButtons = 0; char * buttonName; va_list args; @@ -216,15 +215,17 @@ for (numItems = 0; items[numItems].text; numItems++); - buttonName = button1, numButtons = 0; + buttonName = button1; va_start(args, button1); - while (buttonName) { - buttons[numButtons] = newtButton(-1, -1, buttonName); - numButtons++; - buttonName = va_arg(args, char *); - } + for (buttonName = button1; buttonName; buttonName = va_arg(args, char *)) + ++totalButtons; + va_end(args); - va_end(button1); + buttons = (newtComponent *)alloca(sizeof(newtComponent*)*(totalButtons)); + va_start(args, button1); + for (buttonName = button1; buttonName; buttonName = va_arg(args, char *)) + buttons[numButtons++] = newtButton(-1, -1, buttonName); + va_end(args); buttonBar = newtCreateGrid(numButtons, 1); for (i = 0; i < numButtons; i++) {
Created attachment 43916 [details] program and patch
Your attachment doesn't seem to be a diff -u attachment. Could you reattach it?
added your changes to the current code base. tested ok. thanks for the patch.