summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-07-30 01:31:43 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-07-30 01:31:43 +0000
commit5172e595c90357ff0d66dbda52e58baeaa394336 (patch)
treeb231cc0f115ecf6ae0beed7b9cf21946934c6247 /ext
parent252df14e6befc846d6c7b3b444fc956267440f4d (diff)
* ext/iconv/iconv.c (iconv_convert): append unchanged portion
after overflow. [ruby-dev:21006] * ext/iconv/extconf.rb: check if iconv() 2nd argument is const. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4223 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/iconv/extconf.rb14
-rw-r--r--ext/iconv/iconv.c4
2 files changed, 17 insertions, 1 deletions
diff --git a/ext/iconv/extconf.rb b/ext/iconv/extconf.rb
index b81b737..7176fa4 100644
--- a/ext/iconv/extconf.rb
+++ b/ext/iconv/extconf.rb
@@ -6,6 +6,20 @@ conf = File.exist?(File.join($srcdir, "config.charset"))
conf = with_config("config-charset", enable_config("config-charset", conf))
if have_header("iconv.h")
+ if !try_compile("", "-Werror") or checking_for("iconv() 2nd argument is const") do
+ !try_compile('
+#include <iconv.h>
+size_t
+test(iconv_t cd, char **inptr, size_t *inlen, char **outptr, size_t *outlen)
+{
+ return iconv(cd, inptr, inlen, outptr, outlen);
+}
+', "-Werror")
+ end
+ $defs.push('-DICONV_INPTR_CAST=""')
+ else
+ $defs.push('-DICONV_INPTR_CAST="(char **)"')
+ end
have_library("iconv")
if conf
prefix = '$(srcdir)'
diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c
index 0ff7e0f..cbb89dc 100644
--- a/ext/iconv/iconv.c
+++ b/ext/iconv/iconv.c
@@ -209,7 +209,7 @@ iconv_try
size_t *outlen;
#endif /* HAVE_PROTOTYPES */
{
- if (iconv(cd, (char **)inptr, inlen, outptr, outlen) == (size_t)-1) {
+ if (iconv(cd, ICONV_INPTR_CAST inptr, inlen, outptr, outlen) == (size_t)-1) {
if (!*inlen)
return Qfalse;
switch (errno) {
@@ -401,6 +401,8 @@ iconv_convert
if (!ret)
ret = rb_str_derive(str, instart, inptr - instart);
+ else if (inptr > instart)
+ rb_str_cat(ret, instart, inptr - instart);
return ret;
}