This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug locale/19740] New: mbtowc(3) fails to set errno(2) for incomplete characters


https://sourceware.org/bugzilla/show_bug.cgi?id=19740

            Bug ID: 19740
           Summary: mbtowc(3) fails to set errno(2) for incomplete
                    characters
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: locale
          Assignee: unassigned at sourceware dot org
          Reporter: schwarze at usta dot de
  Target Milestone: ---

Created attachment 9049
  --> https://sourceware.org/bugzilla/attachment.cgi?id=9049&action=edit
patch against stdlib/mbtowc.c to fix errno handling

If an incomplete character is passed to mbtowc(3), it fails to set errno to
EILSEQ, even though that is unambiguously required by POSIX.

Setting errno in that case makes a lot of sense because having a function that
can fail and that sets errno in some failure modes but does not set errno in
other failure modes would be a terrible idea. Such a function would be
ridiculously complicated to use. To detect the reason for failure, you would
have to:

 - save errno
 - reset errno to zero
 - call the function
 - inspect the return value to detect failure
 - inspect errno to decide about the reason for failure
 - if errno is zero, restore the saved errno

That is completely unreasonable, in particular for a seemingly innocous
function like mbtowc(3). Next to no programmer would get that right in any
real-world program.

Note that this bug is very widespread, it also affects FreeBSD and Solaris 11,
and also OpenBSD until i fixed it today. I will also send a note around to the
other systems.

The OpenBSD patch is here:
http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/lib/libc/locale/mbtowc.c

The attachment contains a patch against glibc git master, mainly to make it
even clearer what exactly i mean. Note that i did not test the patch on an
up-to-date glibc-based system since i don't have access to such a system - so
please test before commit! Thanks.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]