- 论坛徽章:
- 0
|
各位高手,我在RHEL5.7 64位机器上用libxml2(2.6.26)的时候遇到了segment fault问题,大家看代码和输出:
代码:- int getNodeCount(xmlXPathContextPtr xpathCtx, char* xpath)
- {
- if(xpathCtx == NULL || xpath == NULL)
- {
- return NULL;
- }
- xmlXPathObjectPtr xpathObj = NULL;
- xmlNodeSetPtr nodeset = NULL;
- xpathObj = xmlXPathEvalExpression((const xmlChar*)xpath, xpathCtx);
- if(xpathObj == NULL)
- {
- return 0;
- }
- nodeset=xpathObj->nodesetval;
- int nodeCount = 0;
- printf("nodesetval : %p, %d\n", nodeset, sizeof(nodeset));
- printf("nodesetval : %p, %d\n", xpathObj->nodesetval, sizeof(xpathObj->nodesetval));
- printf("xpathObj : %p, %d\n", xpathObj, sizeof(xpathObj));
-
- if(nodeset != NULL)
- {
- nodeCount = nodeset->nodeNr;
- }
- xmlXPathFreeObject(xpathObj);
- return nodeCount;
- }
复制代码 输出打印:- nodesetval : 0x1728ee5000000000, 8
- nodesetval : 0x1728ee5000000000, 8
- xpathObj : 0x1728ee00, 8
- Segmentation fault
复制代码 最终出现segment fault的地方是:- nodeCount = nodeset->nodeNr;
复制代码 肯定是因为nodeset无法访问了,但是为什么nodeset的地址长度和xpathObj会不一样呢?
这可如何是好呢?先谢谢大家了。 |
|