2020-11-05-cpp-iconv-字符名称中缺少横杆引发coredump

昨天碰到一个挺无语的问题的,找到问题的时候我自嗨一句:居然还有这种问题。。。

在ubuntu20中编译通过的源码,放到ubuntn16上居然coredump。。。(为何开发用ub20,还要放到u16上?别问,问就是稳定)

定位到是iconv_open的问题,起初还想是不是分配的空间不够大? 编码字串大小写问题? 试了一下都没解决。最后没的怀疑,我就想看看,在那个utf8中间加个横杆试试,乖乖,可以了,但这个问题解决的毫无成就感 >_<

int GbkToUtf8(char * str_str, size_t src_len, char * dst_str, size_t dst_len) {
    iconv_t cd;
    char **pin = &str_str;
    char **pout = &dst_str;

    /* 
     * utf8中必须要有横线,在ubuntu16TLS中编译通过运行coredump,在ubuntu20TLS上没问题
     */
    // cd = iconv_open("utf8", "gbk");
    cd = iconv_open("utf-8", "gbk");
    if (cd == 0) {
        return -1;
    }

    memset(dst_str, 0, dst_len);
    if (int(iconv(cd, pin, &src_len, pout, &dst_len)) == -1) {
        return -1;
    }
    
    iconv_close(cd);

    return 0;
}

我在ubunt16看看了一下,UTF8和UTF-8都是支持的好吧,不过它前面简介倒是说了,列在其中的字符编码可能不可用。
这,这是什么操作?人与人之间的信任呢?。。惨遭社会毒打。。

# iconv -l

The following list contains all the coded character sets known.  This does
not necessarily mean that all combinations of these names can be used for
the FROM and TO command line parameters.  One coded character set can be
listed with several different names (aliases).

...

  UNICODE, UNICODEBIG, UNICODELITTLE, US-ASCII, US, UTF-7, UTF-8, UTF-16,
  UTF-16BE, UTF-16LE, UTF-32, UTF-32BE, UTF-32LE, UTF7, UTF8, UTF16, UTF16BE,
  UTF16LE, UTF32, UTF32BE, UTF32LE, VISCII, WCHAR_T, WIN-SAMI-2, WINBALTRIM,
...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值