[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Corrupted contedt when using utf-8 with Hebrew values in XML
Hi
In my previous conclusion I didn't pay attention to iconv() documentation
that says:
"The variable (pointer) is updated to point to the byte following the last
byte successfully used in the conversion."
However, it says also "If an error occurs during one of the following
requested conversions, the inbuf, inbytesleft, outbuf, and outbytesleft
parameters may not be updated properly."
So, what we have to do is check if p_Data (input pointer) is updated by
iconv(). If not, we have to increment it by the number of bytes already
converted.
it seems to me that the right code of iconvdyn() procedure should be:
(comment = Boaz, are my suggestion for fixes )
P iconvdyn B export
D iconvdyn PI 10I 0
D peSize 10I 0 value
D peData * value
D peDesc 52a
D peOutbuf *
D len s 10I 0
/if not defined(HTTP_USE_TABLES)
D insize s 10U 0
D desc s like(ToAscii)
D p_Data s *
Boaz
D p_outbuf s *
D size s 10U 0
D spaceleft s 10U 0
D GROW_CHUNK C const(65536)
d Ptr@ s *
boaz save p_Data
D ds
D rcU 10U 0
D rcI 10I 0 overlay(rcU)
c eval insize = peSize
c eval size = insize
c eval peOutbuf = xalloc(size)
c eval p_outbuf = peOutbuf
c eval p_Data = peData
Boaz
c eval spaceleft = size
c dow '1'
c eval Ptr@ = p_Data
c eval rcU = iconv( peDesc
c : p_Data
Boaz
c : insize
c : p_outbuf
c : spaceleft )
c if rcI >= 0
c leave
c endif
c if errno <> E2BIG
c callp SetError( HTTP_CONVERR
c : 'CCSID conversion failed: '
c + %str(strerror(errno)) )
c callp xdealloc(peOutbuf)
c return -1
c endif
c eval size = size + GROW_CHUNK
c eval len = p_outbuf - peOutbuf
c eval peOutbuf = xrealloc(peOutbuf:size)
c eval p_outbuf = peOutbuf + len
c eval spaceleft = size - len
c if ptr@ = p_Data
Boaz
c eval p_Data = peData
Boaz skip over
c + (peSize - insize)
converted data
c endif
Boaz
c enddo
c eval len = size - spaceleft
/endif
c return len
P E
Hope this is the right solution to avoid the corruption when going from
single byte code page to multi bytes code page.
Regards
Boaz Mermelstein
3/21 Hershko Avraham st. | Rehovot | Israel
Phone: +972 8 9458690 | Mobile:+972 54 4441 891 | Fax: +972 151 54 4441
891
http://www.smbt.co.il
-----------------------------------------------------------------------
This is the FTPAPI mailing list. To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------