I have written a very simple function to return the match count based on the
simplesearch.cc code. It fails with a seg fault. The relevant code is:
--------------------
int ftQuery(char* qs, const char* dbname,char* results, int msize) {
long docid;
char* op;
char fullDB[1024];
string queryString;
sprintf(fullDB,"/var/lib/fulltext/%s",dbname);
queryString=qs;
try {
Database db;
db.add_database(Database(fullDB));
Enquire enquire(db);
try {
Xapian::QueryParser qp;
Xapian::Stem stemmer("english");
qp.set_database(db);
qp.set_default_op(Query::OP_OR);
qp.set_stemmer(stemmer);
qp.set_stemming_strategy(QueryParser::STEM_SOME);
Xapian::Query q=qp.parse_query(queryString);
...
As soon as it hits the q=qp.parse_query line it gets the seg fault.
The function is called like so:
int main (int argc, char* const argv[]) {
int i;
char results[100000];
if (argc<2) {
printf("Usage: tft 'query string'\n");
return 1;
}
I=ftQuery(argv[1],"testdb",results,2000);
printf("%d results returned\n",i);
return (0);
The query string is "austria" and it works with simplesearch.com. I
have verified that the string is being passed to the function correctly as is
the database name. I am out of ideas and wonder if anyone can point out anything
that I am overlooking.
Thanks,
Michael Lewis
_____________________________________________
Xapian-discuss mailing list
Xapian-discuss at lists.xapian.org
http://lists.xapian.org/mailman/listinfo/xapian-discuss
On Tue, Jan 21, 2014 at 04:53:41PM +0000, Michael Lewis wrote:> I have written a very simple function to return the match count based > on the simplesearch.cc code. It fails with a seg fault. The relevant > code is: > -------------------- > int ftQuery(char* qs, const char* dbname,char* results, int msize) { > long docid;It would be better to use the type Xapian::docid instead of long, though that won't give you a segfault here.> The query string is "austria" and it works with simplesearch.com. I > have verified that the string is being passed to the function > correctly as is the database name. I am out of ideas and wonder if > anyone can point out anything that I am overlooking.Code looks OK - I suspect the problem is elsewhere - e.g. maybe you've corrupted the malloc heap or have a stray pointer write. If you're on a supported platform, I'd run it under valgrind, which can often spot such problems. If you aren't, or that doesn't find anything, run it under gdb and get a backtrace for exactly where the segfault happens - that will likely give more of a clue. Cheers, Olly
Thanks for the response. I ran it under GDB and single stepped the queryparser call. I have a realloc() function in a common module. As soon as I stepped into the query_parser in GDB it called my realloc() instead of the one it was expecting. I removed my routine and it works fine now. Thanks, Michael -----Original Message----- From: Olly Betts [mailto:olly at survex.com] Sent: Tuesday, January 21, 2014 2:29 PM To: Michael Lewis Cc: xapian-discuss at lists.xapian.org Subject: Re: [Xapian-discuss] seg fault on search On Tue, Jan 21, 2014 at 04:53:41PM +0000, Michael Lewis wrote:> I have written a very simple function to return the match count based > on the simplesearch.cc code. It fails with a seg fault. The relevant > code is: > -------------------- > int ftQuery(char* qs, const char* dbname,char* results, int msize) { > long docid;It would be better to use the type Xapian::docid instead of long, though that won't give you a segfault here.> The query string is "austria" and it works with simplesearch.com. I > have verified that the string is being passed to the function > correctly as is the database name. I am out of ideas and wonder if > anyone can point out anything that I am overlooking.Code looks OK - I suspect the problem is elsewhere - e.g. maybe you've corrupted the malloc heap or have a stray pointer write. If you're on a supported platform, I'd run it under valgrind, which can often spot such problems. If you aren't, or that doesn't find anything, run it under gdb and get a backtrace for exactly where the segfault happens - that will likely give more of a clue. Cheers, Olly