【发布时间】:2011-01-08 12:31:05
【问题描述】:
// Returns a list of topic numbers found on the page
vector<string> findTopics(char* rData, int rDataLen) {
pcre *re;
const char *error;
int erroffset;
re = pcre_compile(
"topic/([0-9]+)", /* the pattern */
0, /* default options */
&error, /* for error message */
&erroffset, /* for error offset */
NULL); /* use default character tables */
if(re == NULL) {
printf("Couldn't compile regex (%s)", error);
// exit(-1):
}
int regOf[2];
vector<string> topics;
char *topic;
int offset = 0;
int rc = 1;
// Basically a preg_match_all()
while(true) {
rc = pcre_exec(re, NULL, rData, rDataLen, offset, 0, regOf, sizeof(regOf));
if (rc < 2) {
break;
}
topic = new char[8];
sprintf(topic, "%.*s\n", regOf[2*1+1] - regOf[2*1], rData + regOf[2*1]);
topics.push_back(topic);
offset = regOf[1];
}
pcre_free(re);
return topics;
}
这个函数应该获取一个“主题”列表(匹配topic/[0-9]+),在我解析的特定内容中找到,在rData 中,它几乎可以工作。 topics 填满了它应该填写的主题编号。
当我在 Visual Studio 中调试它时,我在函数结束(返回)后立即收到以下错误消息:运行时检查失败 #2 - 变量“regOf”周围的堆栈已损坏。
我不知道自己做错了什么,想知道是否有人可以为我指出正确的方向。
【问题讨论】:
标签: c++ c memory-leaks pcre