bug-ncurses
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Dialog editbox bug


From: dmitry maybe
Subject: Re: Dialog editbox bug
Date: Sat, 1 Jun 2019 13:44:09 +0000

Sure:

#include "dialog.h"
#include "dlg_keys.h"
#include <cstdlib>
#include <iostream>
#include <cstdio>
#include <stdio.h>

using namespace std;

/*
 *
 */
int main(int argc, char** argv) {
    int status = 0;
    int pos = 1;
    char *server_ip = "";
    char *post_input = "";
    init_dialog(stdin, stdout);
    dialog_vars.nocancel = 0;
    dialog_vars.nook = 0;
    dialog_vars.help_button = 0;
    dialog_state.use_shadow = 0;
                   
   
    while (pos != -1) {
switch (pos) {
   case 1: {
init_dialog(stdin, stdout);
DIALOG_FORMITEM dlg_items_ip[1];
/*
Server input
*/
dlg_items_ip[0].name = "Server:";
dlg_items_ip[0].type = 0;//0 - text, 1- password
dlg_items_ip[0].text = server_ip;
dlg_items_ip[0].help_free = true;
dlg_items_ip[0].name_x = 1;
dlg_items_ip[0].name_y = 1;
dlg_items_ip[0].name_len = 20;
dlg_items_ip[0].name_free = 0;
dlg_items_ip[0].text_flen = 30;
dlg_items_ip[0].text_free = false;
dlg_items_ip[0].text_ilen = 20;
dlg_items_ip[0].text_len = 40;
dlg_items_ip[0].text_x = 10;
dlg_items_ip[0].text_y  = 1;
int r;
status = dlg_form("Sign in","Server:",12,60,0,1,dlg_items_ip,&r);
server_ip = (char *) (malloc(strlen(dlg_items_ip[0].text) + 1));//not forget \0 - the end of C string
strcpy(server_ip, dlg_items_ip[0].text);
if (status == DLG_EXIT_OK ) {
   pos = 2;
}
if (status == DLG_EXIT_CANCEL ) {
   pos = -1;
}
break;
   }
   case 2: {
/*
Post input
*/
init_dialog(stdin, stdout);
int rows;
char **list;
list = (char **) malloc(2+1);
(list)[0] = dlg_strclone("");
(list)[1] = 0;
status = dlg_editbox("Write a post", &list, &rows, 20,30);
post_input = (char *) (malloc(strlen(dialog_vars.input_result) + 1));
strcpy(post_input, dialog_vars.input_result);
if (status == DLG_EXIT_OK ) {
pos = -1;
}
if (status == DLG_EXIT_CANCEL ) {
   pos = 1;
}
break;
   }
}
    }
    end_dialog();
    cout << post_input << endl;
    free(server_ip);
    free(post_input);
    return 1;
}

On Sat, Jun 1, 2019 at 1:04 PM Stian Skjelstad <address@hidden> wrote:
Can you please provide a complete working source code for your current problem? 

On Sat, 1 Jun 2019, 13:58 dmitry maybe, <address@hidden> wrote:
I still it seems like a bug.
So, while debugged, see two crashes cases:
1)After pressed key many times at the same line,
for example "ddddddddddddddddddddddddddddddddddddddddddddddd....."
I've got Segmentation fault in inputsr.c in compare_cache function at line: int result = CMP(p->cache_num, q->cache_num)  (line 130)

2)After input relatively long line,
I've got program crash in editbox.c file in function dlg_editbox at line: free(buffer); (line 744)

On Fri, May 31, 2019 at 9:17 AM dmitry maybe <address@hidden> wrote:
Thank you!
But why characters are showing up as ^@'s ?

On Fri, May 31, 2019 at 8:56 AM Thomas Dickey <address@hidden> wrote:
On Fri, May 31, 2019 at 02:02:17AM +0200, Stian Skjelstad wrote:
> On Fri, 31 May 2019, 01:02 dmitry maybe, <address@hidden> wrote:
>
> >
> >                 char **list;
> >                 list = (char **) malloc(2+1);
> >
>
> list=(char **)malloc(2*sizeof(char *));

perhaps (that seems to be a response to something off-list).

Before looking inside dialog, I'm looking for something that I
can compile and run, so that I can use valgrind (and compiler)
to show me where to look for the actual problem.

The example still has a typo (the ":" in the declaration for tmp_status
should be a ";"), but fixing and compiling that and running it, I don't see
a problem in valgrind:

> g++-min -g -o foo2 foo2.cpp -I/usr/build/ncurses/foo2.cpp -L/usr/build/ncurses/foo2.cpp -ldialog `ncursesw6dev-config --cflags --libs`
cc1plus: warning: /usr/build/ncurses/foo2.cpp: not a directory
foo2.cpp: In function ‘int main(int, char**)’:
foo2.cpp:10:38: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
                 dlg_items_ip[0].name = "Server:";
                                      ^
foo2.cpp:12:38: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
                 dlg_items_ip[0].text = "" ;
                                      ^
foo2.cpp:32:72: warning: operation on ‘status’ may be undefined [-Wsequence-point]
                 status = status=dialog_editbox("Post",input_post,20,30);
                                                                        ^
foo2.cpp:28:5: warning: variable ‘tmp_status’ set but not used [-Wunused-but-set-variable]
 int tmp_status;
     ^

The example shows some problems on the screen which I suppose are due
to problems in the sample code, since the line-drawing characters are
showing up as ^@'s.

--
Thomas E. Dickey <address@hidden>
https://invisible-island.net
ftp://ftp.invisible-island.net

reply via email to

[Prev in Thread] Current Thread [Next in Thread]