bug-ncurses
[Top][All Lists]
Advanced

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

get_wch issue


From: Stéphane Bisinger
Subject: get_wch issue
Date: Sat, 12 Aug 2006 02:12:55 +0100 (BST)

Hi all
I think I found a little bug in the wide-character
functions of ncurses:
if you call get_wch() without setting the CTYPE
locale, it waits forever for new input (or until the
buffer is full, which takes a lot of characters to
happen...).

This happens because the code, as it is structured,
does not check the return value of mblen (or mbrlen)
for errors: if the return value is 0 or more, the
function translates the chars in a wchar, otherwise it
loops again. But there are two different return values
for mblen errors: (size_t)(-2) is for an incomplete
wide-character, (size_t)(-1) for an invalid
wide-character. The latter is what you get if you try
to read a wide-character without setting CTYPE and the
function loops until the buffer is full.

Not calling setlocale(LC_ALL, "") (or similar) before
using wchar functions is a programming error, but the
correct behaviour for a function is to return an error
code, not to wait for more input.

Here are a quick and very dirty program to show you
what happens [1] (I have included and modified the
wget_wch() function to show this particular issue, the
way I found it) and a patch proposition that should
fix this particular issue [2]. I think that there
might be some other similar issues somewhere else,
maybe someone who knows the code better than I do
could tell more.

[1] http://www.sbisinger.net/ncurses/get_wch.tar.bz2
[2] http://www.sbisinger.net/ncurses/lib_get_wch.patch

Regards,

Stéphane


                
___________________________________________________________ 
Inbox full of spam? Get leading spam protection and 1GB storage with All New 
Yahoo! Mail. http://uk.docs.yahoo.com/nowyoucan.html




reply via email to

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