gconv bug and documentation deficiency
Owen Taylor
otaylor@redhat.com
Thu Jan 4 14:01:00 GMT 2001
(Both of these are in glibc-2.2, I have not checked CVS)
The bug:
If you convert from, say, UTF-8 to UCS4le with the length of the output buffer
not a multiple of 4, and smaller than the needed size, then you end up with
errno=EINVAL instead of errno=E2BIG. The problem is the code at the end of
internal_ucs4le_loop[_unaligned]
/* Determine the status. */
if (*inptrp == inend)
result = __GCONV_EMPTY_INPUT;
else if (*outptrp == outend)
result = __GCONV_FULL_OUTPUT;
else
result = __GCONV_INCOMPLETE_INPUT;
The second check needs to be something like:
else if (*outptrp + 4 > outend)
The documentation deficiency:
iconv() can exit with an errno of E2BIG for 2 reasons:
- The output buffer is full
- An internal intermediate buffer is full
This means that a result of E2BIG does not necessarily mean that the
output buffer needs to be expanded. However the docs say:
`E2BIG'
The conversion stopped because it ran out of space in the
output buffer.
Which is confusing. Of course, the wording in the standard is the
same, so its not completely clear that the behavior of glibc here is
legal...
Regards,
Owen
More information about the Libc-alpha
mailing list