在VS2008环境编译
NearbyBusInfo *p = new NearbyBusInfo ;
p->nStationID = 1;
strcpy(p->szName, "测试名称");
strcpy(p->szCarNo,"车牌");
//以下两行会导致堆栈被破坏stack corrupted,
//因为strncpy会写入sizeof(buf) - 1个字节,
//但是写入的开始地址是buf + strlen(buf),导致内存访问越界而破坏堆栈
strncpy(buf + strlen(buf),p->szBusLineName, sizeof(buf) - 1);
strncpy(buf + strlen(buf),p->szCarNo, sizeof(buf) - 1);
//以下两行安全
strncpy(buf + strlen(buf),p->szBusLineName, sizeof(buf) - strlen(buf)-1);
strncpy(buf + strlen(buf),p->szCarNo, sizeof(buf) - strlen(buf)-1);