3 报错怎么解决Exception was raised when calling event-notify Vuser function in extension lrwreplaymain.dll: System Exceptions: EXCEPTION_ACCESS_VIOLATION

代码运行报错


//代码开始

 char * getParam(char * dst, char * src, char * sep, int n)
 
 {
 
 int i = 0, j;
 
 int len;
 
 char * cpy = dst;
 
 char * lp;

 len = strlen(sep);

 while (*src != 0) {

 j = 0;
 
 //遍历字符串src,找到sep第一个字符时停止
 
 while (*src && (*src != *sep)) {
 
 src++;
 
 }

 //记录此时src的指针
 
 lp = src;

 while (*src != 0) {

 src++;
 
 j++;

 //遍历src与sep的字符一一比较,有不同的则退出
 
 if (*src != *(sep + j)) {
 
 break;
 
 }

 //完全匹配时计数i加1
 
 if (j == (len - 1)) {
 
 i++;
 
 break;
 
 }

 }

 //sep出现的次数为n时,赋值至dst并返回
 
 if (i == n) {
 
 lp += len;
 
 while (*lp != '<') {
 
 *dst = *lp;
 
 dst++;
 
 lp++;
 
 }
 
 *dst = 0;

 return cpy;
 
 }
 
 }

 *dst = 0;
 return NULL;
 
 }

 
 char * format (char * dst, char * src, int n)
 
 {
 
 char * id = (char *)malloc(10);
 
 char * name = (char *)malloc(50);
 
 char * sep1 = "<CityID>";
 
 char * sep2 = "<CityName>";

 char * cpy = dst;

 getParam(id, src, sep1, n);
 
 getParam(name, src, sep2, n);
 
 //lr_output_message("id=%s",id);//测试用
 
 //lr_output_message("name=%s",name);//测试用

 //按格式拼接字符串
 
 //if ((id != NULL) && (name != NULL)) {
 if ((strcmp(id,"")!=0) && (strcmp(name,"")!=0)) {
 
 strcpy(dst, "{\"CityID\":\"");
 
 strcat(dst, id);
 
 strcat(dst, "\",\"CityName\":\"");
 
 strcat(dst, name);
 
 strcat(dst, "\"}");

 free(id);
 
 free(name);

 return cpy;
 
 }

 *dst = 0;
 return NULL;
 
 }
Action()
{
 long fp; 
 int total = 0;
 int readbufsize = 0;
 int count = 0;
 int i = 0;
 int ii = 1;
 char * fmtstr = (char *)malloc(100);
 char * xmlstr = (char *)malloc(100);
 char *readbuf;
 char *file = "C:\\data.xml";

 //读取XML文件
if ( (fp = fopen(file, "r")) == NULL)
 {
 lr_message("open logfile failed!\n");
 return -1;
 } 

 //申请 readbuf
    readbuf = (char*) calloc(50, sizeof(char));

 if (readbuf == NULL)
 {
 lr_message("Insufficient memory available");
 return -1;
 }

 //循环读取文件
while(!feof(fp))
 {
 // 扩展缓冲区
if( readbufsize - total <= 10 )
 {
 readbufsize += 100;
 readbuf = (char*) realloc(readbuf, readbufsize);
 }

 count = fread(readbuf + total, sizeof(char), 10, fp);

 total += count;
 }

 //关闭文件句柄
fclose(fp);

 //修改readbuf内存值
readbuf = (char*) realloc(readbuf, readbufsize+1);
        *(readbuf+total) = '\0';

 //保存参数  
lr_save_string(readbuf,"readbuf_param");
//lr_output_message(readbuf);
lr_convert_string_encoding(lr_eval_string("{readbuf_param}"),"utf-8",NULL,"read");
//lr_output_message("%s",lr_eval_string("{read}"));
strcpy(xmlstr, lr_eval_string("{read}"));
 
 
 
 
 while (1) {
 
 format (fmtstr,xmlstr, ii);
 
 //if (fmtstr != NULL) {
 if (strcmp(fmtstr,"")!=0) {

 
 lr_output_message(fmtstr);
 
 ii++;
 
 }
 
 else
 
 break;
 
 }
}


请先 登录 后评论

莫言 - 高级测试

擅长:性能测试

调用函数异常,是你的环境问题吧

请先 登录 后评论
  • 1 关注
  • 0 收藏,595 浏览
  • 鲁德-晓兰 提出于 2019-08-13 15:23

相似问题

360网站安全检测平台