Re: striconveh: Ensure that none of the offsets[] are out-of-range

Bruno Haible via Gnulib discussion list <[email protected]>
Newsgroups gmane.comp.lib.gnulib.bugs
Message-ID <3345941.l5Z5W5aWdd@cagnes>
I did:
> 2026-08-16  Bruno Haible  <[email protected]>
> 
> 	striconveh: Ensure that none of the offsets[] are out-of-range.

Now, the CI reports a test failure on those platforms that use a non-GNU
implementation of iconv():

FAIL: test-u16-conv-to-enc
==========================

../../gltests/uniconv/test-u16-conv-to-enc.c:165: assertion 'offsets[0] == (size_t)(-1)' failed
FAIL test-u16-conv-to-enc (exit status: 1)


This patch fixes it.


2026-08-18  Bruno Haible  <[email protected]>

	u16-conv-to-enc: Ensure that none of the offsets[] are out-of-range.
	* lib/uniconv/u-conv-to-enc.h (FUNC): Don't assign an offsets[i] at the
	incomplete sequence at the end.

diff --git a/lib/uniconv/u-conv-to-enc.h b/lib/uniconv/u-conv-to-enc.h
index 9467fa8952..96c35039f0 100644
--- a/lib/uniconv/u-conv-to-enc.h
+++ b/lib/uniconv/u-conv-to-enc.h
@@ -136,7 +136,10 @@ FUNC (const char *tocode,
          incomplete sequence of units at the end.  */
       if (iunit < srclen)
         {
-          offsets[iunit] = *lengthp;
+          /* NOT
+               offsets[iunit] = *lengthp;
+             because the caller expects that all assigned offsets[i]
+             are < *lengthp.  */
           if (!(U_MBLEN (src + iunit, srclen - iunit) < 0))
             abort ();
         }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.