我正在调用一个函数parse_consol(definition1);其中定义,即传递的参数是 char* 类型,并且是 xml 文件的绝对路径。当我检查(通过调试)传递的值绝对正确,但是当控制函数的定义时,它所采用的值会在末尾附加一些随机字符,这会导致失败。
我需要知道这些字符是如何附加到函数定义中实际参数的末尾的。
下面评论中的代码:
definition_state1 = (char*)malloc(((int) strlen(((char*)definition_path)+1)));
strcpy(definition_state1 ,(char*)definition_path);
definition_state2 = (char*)malloc(((int) strlen(((char*)value[1])+1)));
strcpy(definition_state2 ,(char*)value[1]);
strcat(definition_state1,definition_state2);
get_license_properties("D:\\Automation\\InputFiles\\current_state\\c2v1.c2v"); // parser for decoded c2v
parse_consolidated(definition_state1); // parser for consolidated xm
最佳答案
很可能您溢出了 definition_state1
缓冲区。您分配了 definition_path+1
缓冲区并将 definition_path
复制到缓冲区中。然后,您将 definition_state2
附加到此缓冲区,这肯定会溢出 definition_state1
缓冲区。
关于c - 一些额外的字符被添加到传递给函数的参数中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16706477/