惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

U
Unit 42
T
The Blog of Author Tim Ferriss
H
Help Net Security
博客园 - 叶小钗
云风的 BLOG
云风的 BLOG
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
D
DataBreaches.Net
博客园 - 聂微东
A
About on SuperTechFans
大猫的无限游戏
大猫的无限游戏
P
Proofpoint News Feed
Martin Fowler
Martin Fowler
博客园 - 【当耐特】
S
SegmentFault 最新的问题
Blog — PlanetScale
Blog — PlanetScale
酷 壳 – CoolShell
酷 壳 – CoolShell
G
Google Developers Blog
I
InfoQ
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
GbyAI
GbyAI
B
Blog
Engineering at Meta
Engineering at Meta
V
V2EX
Hugging Face - Blog
Hugging Face - Blog

博客园 - shareach

博客搬家了,欢迎访问 http://blog.csdn.net/yinpengxiang/ IOS Storyboard使用-模拟登录、注册、混合使用 XCode 细点 蛋痛的C#和.net,采集问题(小数点) Mapbar POI 转 经纬度坐标的各个版本 MongoDB的主键类型修改,记录下 Android 自动化功能测试神器ChimpChat(MonkeyRunner) MongoDB的GeoSpatial索引 之 GeoNear命令,取得距离 MongoDB的GeoSpatial索引 Android + HTML开发手机应用 demo 代码 commonsware-Android平台可复用代码仓库 jqMobi + Android 试手 服务端通过设置 响应头允许其他域名跨域访问数据 Android上 用Html5做界面,javascript调用摄像头实例 Android 拍照加剪切处理方式 css3替代图片的尖角圆角效果 抛弃作为mongoDB做主存储的一些关键因素 ibatis3.06 + spring 3.06+velocity 整合的VSSI框架测试 基于即时更新的缓存策略设计草稿
.Net C# 的一个bug(暂时命名为Bug)
shareach · 2012-10-26 · via 博客园 - shareach

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

/// <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 写了点就报这个错,伤不起。