From 0a36c0e86b39d9e64ded167eec21408c27e089c8 Mon Sep 17 00:00:00 2001 From: Tim Kientzle Date: Sun, 8 Aug 2004 02:22:48 +0000 Subject: [PATCH] Oops. Use "unsigned long" instead of "int" for the intermediate variables in wide-character conversions, since it's guaranteed to be large enough. Thanks to: Andrey Chernov --- lib/libarchive/archive_read_support_format_tar.c | 2 +- lib/libarchive/archive_write_set_format_pax.c | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/libarchive/archive_read_support_format_tar.c b/lib/libarchive/archive_read_support_format_tar.c index 76a228ee09fd..e91ddc47b0aa 100644 --- a/lib/libarchive/archive_read_support_format_tar.c +++ b/lib/libarchive/archive_read_support_format_tar.c @@ -1519,7 +1519,7 @@ static size_t UTF8_mbrtowc(wchar_t *pwc, const char *s, size_t n) { int ch, i, len, mask; - int lbound, wch; + unsigned long lbound, wch; if (s == NULL) /* Reset to initial shift state (no-op) */ diff --git a/lib/libarchive/archive_write_set_format_pax.c b/lib/libarchive/archive_write_set_format_pax.c index 307ee1d7765c..f5ee4c67663e 100644 --- a/lib/libarchive/archive_write_set_format_pax.c +++ b/lib/libarchive/archive_write_set_format_pax.c @@ -188,15 +188,13 @@ add_pax_attr_w(struct archive_string *as, const char *key, const wchar_t *wval) { int utf8len; const wchar_t *wp; - int wc; + unsigned long wc; char *utf8_value, *p; utf8len = 0; for (wp = wval; *wp != L'\0'; ) { wc = *wp++; - if (wc <= 0) { - /* Ignore negative values. */ - } else if (wc <= 0x7f) + if (wc <= 0x7f) utf8len++; else if (wc <= 0x7ff) utf8len += 2; @@ -206,16 +204,15 @@ add_pax_attr_w(struct archive_string *as, const char *key, const wchar_t *wval) utf8len += 4; else if (wc <= 0x3ffffff) utf8len += 5; - else + else if (wc <= 0x7fffffff) utf8len += 6; + /* Ignore larger values; UTF-8 can't encode them. */ } utf8_value = malloc(utf8len + 1); for (wp = wval, p = utf8_value; *wp != L'\0'; ) { wc = *wp++; - if (wc <= 0) { - /* Ignore negative values. */ - } else if (wc <= 0x7f) { + if (wc <= 0x7f) { *p++ = (char)wc; } else if (wc <= 0x7ff) { p[0] = 0xc0 | ((wc >> 6) & 0x1f); @@ -248,6 +245,7 @@ add_pax_attr_w(struct archive_string *as, const char *key, const wchar_t *wval) p[4] = 0x80 | (wc & 0x3f); p += 6; } + /* Ignore larger values; UTF-8 can't encode them. */ } *p = '\0'; add_pax_attr(as, key, utf8_value);