Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8380827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:33:21+00:00 2026-06-09T16:33:21+00:00

The segmentation fault is caused in the scanner code. The Problem: Using GDB to

  • 0

The segmentation fault is caused in the scanner code.

The Problem:

Using GDB to backtrack reveals that the problem is caused with the declaration of the FieldInfo Pointer named field_info (where FieldInfo is a struct) in the condition: if (tell_me).

Please note the the following code is a part of a large file, so if there are some things whose declaration is not here, you can probably assume that they would have been defined in the program somewhere else and not shown here.

The sample code:

Some_function(some_arguments) {    
// Did something.

if (flag_1) {

    list<const FieldInfo *> prefix_stack;

    const FieldInfo def_pfx(NON_BOOLEAN, default_prefix);
    {
    const FieldInfo * default_field_info = &def_pfx;
    if (default_prefix.empty()) {
        map<string, FieldInfo>::const_iterator f = field_map.find("");
        if (f != field_map.end()) default_field_info = &(f->second);
    }

    // We always have the current prefix on the top of the stack.
    prefix_stack.push_back(default_field_info);
    }

    // Did something.

    for (<some conditions>) {
        bool tell_me = false;
        // Did something.

        if (tell_me) {
            const FieldInfo pos_prefix(NON_BOOLEAN, pos);
            const FieldInfo * field_info = &pos_prefix;
            Term * term_obj = new Term(&state, term_lowercase, field_info, 
                                            term, stem_term, term_pos++);
            Parse(pParser, token, term_obj, &state);
        } else {
            const FieldInfo * field_info = prefix_stack.back();
            Term * term_obj = new Term(&state, term_lowercase, field_info, 
                                            term, stem_term, term_pos++);
            Parse(pParser, token, term_obj, &state);
        }

        // Did something.
    }
}

// Did something.
}

And the definition of FieldInfo is:

struct FieldInfo {
/// The type of this field.
filter_type type;

/// Field prefix strings.
list<string> prefixes;

/// Field processors struct already defined earlier.
list<FieldProcessor*> procs;

FieldInfo(filter_type type_, const string & prefix)
: type(type_)
{
prefixes.push_back(prefix);
}

FieldInfo(filter_type type_, FieldProcessor *proc)
: type(type_)
{
procs.push_back(proc);
}

};

Analysis:

Parse is a method that calls the Parser.

GDB reveals that the problem (segmentation fault) is caused when the Parser tries to process the field_info by iterating over the field_info->prefixes.

EDIT:

Here is the code of the function where the segmentation fault occurs (I have added some cout for the debugging purposes). The problem comes is in the while (++piter != prefixes.end()) part of code:

Query get_query() const
{
    const list<string> & prefixes = field_info->prefixes;

    if (prefixes.empty()) {
    assert(!field_info->procs.empty());
    return (**field_info->procs.begin())(name);
    }
    list<string>::const_iterator piter = prefixes.begin();
    Query q(make_term(*piter), 1, pos);
    while (++piter != prefixes.end()) {
    string check3 = make_term(*piter);
    Query q2(check3, 1, pos);
    q = Query(Query::OP_OR, q, q2);
    }
    return q;
}

NOTE:

I am working on some-one else’s working code.

I have added the if(flag_1) part of code, and rest everything else was there already.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T16:33:22+00:00Added an answer on June 9, 2026 at 4:33 pm

    This part looks suspicious:

    const FieldInfo pos_prefix(NON_BOOLEAN, pos);
    const FieldInfo * field_info = &pos_prefix;
    Term * term_obj = new Term(&state, term_lowercase, field_info, 
                               term, stem_term, term_pos++);
    

    You are using the address of the local variable pos_prefix to initialize term_obj. You have to make absolutely sure that this address is never accessed after pos_prefix has gone out of scope, because then the address will be invalid.

    You are having an awful lot of raw pointers in your code. This is not good practice in modern C++. Consider using plain objects, references or smart-pointers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to debug a segmentation fault caused by my C program using
The following code causes a segmentation fault. The executable is named './struct' #include <stdio.h>
This c code crash with a segmentation fault if I compile with GCC using
This code causes a Segmentation Fault: int main(){ char *p; char a[50] = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
Is there any reason why printw() would cause a segmentation fault? Code is fine
I have segmentation fault problem with my multiple class files project. Without making empty
I am getting segmentation fault in this code but i cant figure out why.
I have a segmentation fault in the code below, but after I changed it
further developing the code from yesterday ( seg fault caused by malloc and sscanf
I'm having trouble with a segmentation fault caused by the following line: heapVec[currentsize] =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.