我对C ++和Lotus笔记知之甚少。我有一段代码在日志中打印组名。
Util::AgentDebug("In Command::InitGroupMap(): Group Name = %s",lnGrpName.GetBuf());
lnGrpName是LNstring。它运行正常,但每当组名长度超过2200时,它就会崩溃。
这是一个例子 - 假设组名是
asd.Storage.Implementation;任务mnncpohcpg01;任务paersc2hcpg01; azscotns02a; azscotns02b; ctshelns02a; ctshelns02b; flschons03a; flschons03b; iadubqns02a; iadubqns02b; mnncpoba0015; mnncpobrcd01; mnncpoisobrcd01; mnncpoisobrcd02; mnncpoisov7k01; mnncpolto01; mnncpolto01_1; mnncpolto01_imc; mnncpons03a; mnncpons03b; mnncpons900a_asd; mnncpons900b_asd; mnncpons900c; mnncpons900c_asd; mnncpons900d; mnncpons900d_asd; mnncpons900_asd; mnncpons900_sw1; mnncpons900_sw2; mnncposanc100; mnncposanc200; mnncposanr150; mnncposanr250; mnncposvc01; MNNCPOFL9KR01; MNNCPOFL9KR02; MNNCPONS900_sw1; MNNCPONS900_sw2; njmadins01a; njmadins01b; njros1ns05ta; njros1ns05tb; njwoodns05a; njwoodns05b; NJCTMVSP01; p2erscba0145; paersc1ns900a_asd; paersc1ns900b_asd; paersc1ns900c; paersc1ns900d; paersc1ns900_sw1; paersc1ns900_sw2; paersc2ns900a_asd; paersc2ns900b_asd; paersc2ns900c; paersc2ns900d; paersc2ns900_sw1; paersc2ns900_sw2; paersc2ocum01; paersc2opm01; paerscns05; paerscnsv501a; paerscnsv501b; PACTMVSP01; PAERSC1FL9KR01; PAERSC1FL9KR02; PAERSC1LABBRCD01; PAERSC1LABBRCD02; PAERSC1LABSVC01; PAERSC2FL9KR01; PAERSC2FL9KR02; PAERSC2FL9KR03; PAERSC2LABBRCD01; PAERSC2LABBRCD02; PAERSC2LABSVC01; txdallns02a; txdallns02b; MNNCPOBA0014; paerscsvc03; njros1svc01; njros1svc02; p1ehowld202; p1ehowld203; p2ehowld202; p2ehowld203; mnncpold202; mnncpold203; MNNCPONS805_asd; MNNCPONS805a_asd; MNNCPONS805b_asd; MNNCPONS805b_asd; paersc2ns805_asd; paersc2ns805a_asd; paersc2ns805b_asd; mnncpob15k01; paersc1g15k01; paersc2g15k01; paersc2sane103; paersc2sane203; P2ERSCBA0305; MNNCPOBA0277; P2ERSCAPL0005; MNNCPOAPL0016; p2erscba0147; mnncpoba0016; MNNCPOECSCN01; PAERSC2ECSCN01; PAERSC2FLAR900_1; P2ERSCAPL0006; njros1labcisc100; njros1labcisc200; p1erscba0402; paersc2ns700_sw1; paersc2ns700_sw2; paersc2ns700a_asd; paersc2ns700b_asd; paersc2ns700_asd; paersc1ns700_sw1; paersc1ns700_sw2; paersc1ns700a_asd; paersc1ns700b_asd; paersc1ns700_asd; mnncpons700_sw1; mnncpons700_sw1; mnncpons700_sw2; mnncpons700a_asd; mnncpons700b_asd; mnncpons700c_asd; mnncpons700d_asd; mnncpons700_asd; p2erscba0346; p2erscba0146; paersc1ns500; paersc1ns500a_asd; paersc1ns500b_asd; paersc2ns500; paersc2ns500a_asd; paersc2ns500b_asd
这个问题是因为LNString还是GetBuf()?
AgentDebug方法如下 -
void Util::AgentDebug( wchar_t * format , ... )
{
wchar_t tmp[2048];
va_list args;
char strBuff[4096];
int j = 0;
va_start(args, format);
vswprintf_s(tmp, format, args);
va_end(args);
int cnt = wcstombs(strBuff, tmp, 4095);
if(cnt < 0)
{
char *strInput = (char*)tmp;
for( int i = 0; i < (wcslen(tmp) * 2); i++ )
{
if(strInput[i] != 0)
strBuff[j++] = strInput[i];
}
strBuff[j] = '\0';
}
// AdkDebug (strBuff);
// Fix for IY98698 Certain Chinese character throws exception during recon (PMR10927999672)
// String to be logged is passed as second arguement
AdkDebug("%s",strBuff);
}// end of func AgentDebug()
// end S15302
有什么替代方案,因为我想在日志中打印组名。
这看起来更像是一个团体成员列表而不是一个团体名称,但是好吧......
我的C ++和va_args的东西很生疏,但它看起来像你的tmp数组只能容纳2048个wchar_t,我认为你需要一个wchar_t用于null终止符,你的格式大约有40个字符串。因此,当你传入一个长度为2200的字符串时,你会溢出tmp。如果我的数字是正确的话,你会用长度超过2007的任何东西溢出它。
我在想同样的事?一个组名只要2200个字节或字符?好。我不知道如何“修复”你的问题,但假设你无法真正“修复”它,“修复”它我会截断字符串或将字符串添加为两个值。如果字符串长于2150,请将其分解为两个字符串并将它们写入日志。只是一个想法。没有更多信息就无法做得更多。