Hello, I found a testxlate in the test dir of apr-util, which is not build and fails to correctly convert to UTF-7.
One reason is, that the trailing '\0' is translated to. An other is, that iconv cannot convert (in some cases) a buffer completly without knowing, that the string really ends at the end of inbuf. This only affects encodings, where in one (encoded) byte may be information for more then one decoded byte (i.e. UTF-7). Below comes a log and a patch. I assume, that apr_xlate_conv_buffer should convert inbuf and assume, that the strings ends then. Else its use in test/testxlate.c is not appropriate. (I'm on GNU/Linux using gcc 3.3.4 (Debian 1:3.3.4-13)) Below is the log message and an patch is attached. Regards Uwe BTW: you will not need the .cvsignore files, which are in the subversion repo, any more. [[ Fix apr_xlate_conv_buffer when using iconv() * xlate/xlate.c (apr_xlate_conv_buffer): terminate conversion correctly by adding the terminal shift sequence. * test/Makefile.in add a build rule for testxlate and add testxlate to PROGRAMS * test/testxlate.c (test_conversion): instead of converting the trailing '\0', append a '\0' to the result. ]] -- Uwe Zeisberger http://www.google.com/search?q=2004+in+roman+numerals
Index: xlate/xlate.c
===================================================================
--- xlate/xlate.c (revision 76237)
+++ xlate/xlate.c (working copy)
@@ -342,6 +342,10 @@
translated = iconv(convset->ich, (ICONV_INBUF_TYPE)&inbufptr,
inbytes_left, &outbufptr, outbytes_left);
+ if (translated != (apr_size_t)-1)
+ translated += iconv(convset->ich, NULL, NULL,
+ &outbufptr, outbytes_left);
+
/* If everything went fine but we ran out of buffer, don't
* report it as an error. Caller needs to look at the two
* bytes-left values anyway.
Index: test/Makefile.in
===================================================================
--- test/Makefile.in (revision 76237)
+++ test/Makefile.in (working copy)
@@ -3,7 +3,7 @@
INCLUDES = @APRUTIL_PRIV_INCLUDES@ @APR_INCLUDES@ @APRUTIL_INCLUDES@
PROGRAMS = testall testdbm testdate testmd4 testmd5 testxml testrmm \
- testreslist testqueue
+ testreslist testqueue testxlate
TARGETS = $(PROGRAMS)
[EMAIL PROTECTED]@
@@ -66,6 +66,11 @@
testqueue: $(testqueue_OBJECTS) $(testqueue_LDADD)
$(LINK) $(APRUTIL_LDFLAGS) $(testqueue_OBJECTS) $(testqueue_LDADD)
$(PROGRAM_DEPENDENCIES)
+testxlate_OBJECTS = testxlate.lo
+testxlate_LDADD = $(TARGET_LIB_PATH)
+testxlate: $(testxlate_OBJECTS) $(testxlate_LDADD)
+ $(LINK) $(APRUTIL_LDFLAGS) $(testxlate_OBJECTS) $(testxlate_LDADD)
$(PROGRAM_DEPENDENCIES)
+
testall_OBJECTS = teststrmatch.lo testuri.lo testuuid.lo abts.lo testutil.lo \
testbuckets.lo testpass.lo
testall_LDADD = $(TARGET_LIB_PATH)
Index: test/testxlate.c
===================================================================
--- test/testxlate.c (revision 76237)
+++ test/testxlate.c (working copy)
@@ -46,13 +46,14 @@
{
static char buf[1024];
int retcode = 0;
- apr_size_t inbytes_left = strlen(inbuf) + 1;
+ apr_size_t inbytes_left = strlen(inbuf);
apr_size_t outbytes_left = sizeof(buf) - 1;
apr_status_t status = apr_xlate_conv_buffer(convset,
inbuf,
&inbytes_left,
buf,
&outbytes_left);
+ buf[sizeof(buf) - outbytes_left - 1] = '\0';
retcode |= check_status(status, "apr_xlate_conv_buffer");
if ((!status || APR_STATUS_IS_INCOMPLETE(status))
&& strcmp(buf, expected))
signature.asc
Description: Digital signature
