zoukankan      html  css  js  c++  java
  • .Net C# 的一个bug(暂时命名为Bug)

    见下面函数,是一个写入发送缓冲区队列的函数

    /// <summary>
    /// 发送缓存区
    /// </summary>
    /// <param name="content"></param>
    /// <param name="bufferOffset"></param>
    /// <param name="senderBuffer"></param>
    private void WriteSendBuffer(string content,int bufferOffset, byte[] sendBuffer)
    {
        int byteLength = Encoding.UTF8.GetByteCount(content);
        if (byteLength <= sendBuffer.Length)
        {
            byte[] sendBytes = Encoding.UTF8.GetBytes(content);
            //中午就会错误的  Encoding.UTF8.GetBytes(content, 0, byteLength, senderBuffer, bufferOffset);
            //以上换成数组拷贝就木问题了
            Array.Copy(sendBytes, 0, sendBuffer, bufferOffset, byteLength);  // 拷贝到数据包缓冲区
        }
    }

    注意到UTF8的GetBytes,content里没中文一点问题都没有,如果是ASCII也木问题,但是如果用Unioncode且有中文就直接数组越界,错误信息是:

    索引和计数必须引用该字符串内的位置

    估计这是.Net里面的一个Bug,反正肯定是中文字节没处理好,有分析原理的么?

    好久没写.net 写了点就报这个错,伤不起。

  • 相关阅读:
    python的logging库
    python的os库
    python的setup和teardown
    CF339D Xenia and Bit Operations线段树
    poj3311Hie with the Pie状压dp
    poj3254Corn Fields状压Dp
    CF414BMashmokh and ACMDP
    母函数6连杀
    母函数hdu1085
    UVA 1401Remember the WordDp
  • 原文地址:https://www.cnblogs.com/yinpengxiang/p/2740434.html
Copyright © 2011-2022 走看看