Bug#197416: detailed problem description and a patch (workaround)

Sergey Spiridonov Sergey Spiridonov <sena@hurd.homeunix.org>, 197416@bugs.debian.org
Thu, 05 Feb 2004 18:20:54 +0100

This is a multi-part message in MIME format.
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit


After hacking a bit, I found out, that the problem is caused by libpopt.

Libpopt uses char to calculate line lengths (it needs to calculate line
lengths because of the wrapping it does during help output). Libpopt 
assumes 79 chars as maximum width of the line on the screen. It looks 
for the option+description with maximum length in chars.

It is already wrong, since Russian text uses UTF-8, and in UTF-8 four 
chars(bytes) can be displayed as one character on the screen. Anyway,
after finding out the length, libpopt calculates some offsets. The
offset becomes negative. This negative value is used for mallocs, 
pointer arithmetics and so on.

The patch below, just fixes the line, where the offset becomes negative,
so gconftool-2 does not produce megabytes of garbage on stdout.
It is not best solution. The best solution will be to
1. rewrite libopt to handle UTF-8 properly (for example using wchar)
2. rewrite help output formatting (with the attached patch Russian help
will not be formatted very nice).

Best regards, Sergey Spiridonov

Content-Type: text/x-patch;
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;

--- popthelp.c.old	2004-02-05 18:14:11.000000000 +0100
+++ popthelp.c	2004-02-05 18:13:48.000000000 +0100
@@ -201,7 +201,7 @@
 	/*@modifies *fp, fileSystem @*/
     int indentLength = maxLeftCol + 5;
-    int lineLength = 79 - indentLength;
+    int lineLength = (indentLength > 78) ? 1 : (79 - indentLength) ;
     const char * help = D_(translation_domain, opt->descrip);
     const char * argDescrip = getArgDescrip(opt, translation_domain);
     int helpLength;