Re: [Iup-users] In C: IupGetText / IupText with MULTILINE=YES question - how to set maximum input l
Brought to you by:
scuri
From: Antonio S. <sc...@te...> - 2010-02-23 19:09:00
|
This is a bug in NC. As a workaround you can set NC after the dialog is mapped that it will work. Best, scuri > -----Original Message----- > From: Stefan Giesen [mailto:ig...@ro...] > Sent: terça-feira, 23 de fevereiro de 2010 15:00 > To: IUP Users Mailing List > Subject: [Iup-users] In C: IupGetText / IupText with MULTILINE=YES > question - how to set maximum input length? > > Hi all, > > I just started with IUP (I downloaded the current release 3.0 from SF > yesterday) and I wasn't able to find anything in the documentation > and/or > mailing list about how to set the maximum keyboard input length for > IupText > with MULTILINE=YES (and for the predefined dialog IupGetText, for that > matter). > > If I use IupText with MULTILINE=NO, I can set the maximum keyboard > input > length with NC=<length> (e.g. "NC=20" for 20 characters). This is fine > to > prevent input buffer overflows if I use IupSetAttribute for the VALUE > field > with my own text buffer pointer (as long as you remember the '\0' at > the > end of the string, which means that the text buffer has to have 21 > characters if you need 20 characters). > > But when I use the multi-line mode of IupText, the "NC" attribute is > completely ignored (and if I check it after displaying the dialog, > there > are strange values in it, like e.g. 136705248 or 136723456, see below). > I've appended my little test program (which uses nearly the same code > as > used in iup_predial.c for IupGetText). > > If you comment out line 25: > > IupSetAttribute(multi_text, "MULTILINE", "YES"); > > everything works as expected, you can't input more than 20 characters > in > the dialog. > > But if multi-line mode is used, you can enter as much text as you want > in > the text area (and the program segfaults immediately after clicking > "OK" - > as to be expected, since my text input buffer only has 21 bytes): > > $ ./test1 > NC=136705248 > Segmentation fault > $ ./test1 > NC=136723456 > Segmentation fault > > Is there any possibility to specify the maximum keyboard input in > multi-line mode? I'm quite sure it's not a good idea to maximize my via > malloc allocated text buffer to 2^31 characters to prevent segfaults... > 8-) > > Yes, I know that I could have used IupStoreAttribute (instead of > IupSetAttribute with a pointer to my own text buffer) for VALUE and > used > strncpy with my maximum length instead of strcpy after the dialog was > closed - but I think this would be bad behavior regarding user > usability: > the user was able to enter 1000 characters and the result he gets into > the > program is just 20 characters after closing the dialog... He will > think: > what the hell is going on? If the program only wants 20 characters in > multi-line, I should be able to configure that in IUP (and the problem > with > IupGetText would be still the same, because i can't do anything about > the > buffer, see iuppredial.c). > > Is there maybe something I have missed in the documentation? Or is this > a > bug/missing feature in IUP? > > Thanks in advance, > Stefan > > > ----------------------------------------------------------------------- > ------- > Download Intel® Parallel Studio Eval > Try the new software tools for yourself. Speed compiling, find bugs > proactively, and fine-tune applications for parallel performance. > See why Intel Parallel Studio got high marks during beta. > http://p.sf.net/sfu/intel-sw-dev > _______________________________________________ > Iup-users mailing list > Iup...@li... > https://lists.sourceforge.net/lists/listinfo/iup-users |