diff options
author | kientzle <kientzle@FreeBSD.org> | 2004-08-08 02:22:48 +0000 |
---|---|---|
committer | kientzle <kientzle@FreeBSD.org> | 2004-08-08 02:22:48 +0000 |
commit | 6b8c5a5e67931e028e3dc8aaee14961eda10dab8 (patch) | |
tree | 183f73ec4ffe4124683eedb00456daec1079c2d4 /lib/libarchive/archive_write_set_format_pax.c | |
parent | 92956ea0cd6a94375374708ae3ac9ef76311b0ca (diff) | |
download | FreeBSD-src-6b8c5a5e67931e028e3dc8aaee14961eda10dab8.zip FreeBSD-src-6b8c5a5e67931e028e3dc8aaee14961eda10dab8.tar.gz |
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
Diffstat (limited to 'lib/libarchive/archive_write_set_format_pax.c')
-rw-r--r-- | lib/libarchive/archive_write_set_format_pax.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/lib/libarchive/archive_write_set_format_pax.c b/lib/libarchive/archive_write_set_format_pax.c index 307ee1d..f5ee4c6 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); |