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 6020569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:35:16+00:00 2026-05-23T03:35:16+00:00

It works with Visual Studio, but segfaults in Cygwin, which is weird because I’m

  • 0

It works with Visual Studio, but segfaults in Cygwin, which is weird because I’m compiling the same source, and both generate a Windows executable. GDB doesn’t work very well for me in Cygwin for some reason, and the error doesn’t appear in VS so I can’t really debug it there.

Any ideas?

int main(void)
{
    Pair ***occurences = new Pair**[20];

    int i, j, k;
    for (i = 0; i < 20; i++)
    {
        occurences[i] = new Pair*[i+1];

        for (j = 0; j < i+1; j++)
        {
            occurences[i][j] = new Pair[26];

            for (k = 0; k < 26; k++)
            {
                Pair pair;
                pair.c = k + 'a';
                pair.occurs = 0;
                occurences[i][j][k] = pair;
            }
        }
    }

    std::fstream sin;
    sin.open("dictionary.txt");
    std::string word;

    while (std::getline(sin, word))
    {
        if (word.size() < 21)
        {
            for (i = 0; i < word.size(); i++)
            {
                // SEGFAULTING HERE
                occurences[word.size()-1][i][word[i] - 'a'].occurences++;
            }
        }
    }

    for (i = 0; i < 20; i++)
    {
        for (j = 0; j < i+1; j++)
        {
            delete [] occurences[i][j];
        }
        delete [] occurences[i];
    }
    delete [] occurences;

    return 0;
}
  • 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-05-23T03:35:17+00:00Added an answer on May 23, 2026 at 3:35 am

    You marked this line as the critical point:

    occurences[word.size()-1][i][word[i] - 97].occurs++;
    

    All three array accesses might go wrong here, and you would have to check them all:

    It seems like the first dimension of the array has the length 20, so the valid values for the index are [0..19]. word.size()-1 will be less than 0 if the size of the word is zero itself, and it will be larger than 19 if the size of the word is 21 or more.

    Are you sure the length of the word is always in the range [1..20]?

    The second dimension has variable length, depending on the index of the first dimension. Are you sure this never gets out of bound?

    The third dimension strikes me as the most obvious. You subtract 97 from the character code, and use the result as index into an array with 26 entries. This assumes that all characters are in the range of [97..122], meaning [‘a’..’z’]. Are you sure that there will never be other characters in the input? For example, if there are any capital characters, the resulting index will be negative.

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

Sidebar

Related Questions

Uploadify works for Visual Studio but not for IIS 7 (same machines), using Forms
The following code works with Visual Studio 2008 but not with GCC/G++ 4.3.4 20090804.
For instance, winsock libs works great across all versions of the visual studio. But
It works on my development serve within Visual Studio 2010 but when I deploy
The following code works on Visual Studio 2005, but gives me a compiler error
I've found that the following code doesn't compile in Visual Studio 2010 (but works
I have an asp.net mvc application that works fine under visual studio but when
Using IIS7.5, the website works fine in Visual Studio but when I try to
The below code works on Visual Studio 2008 with and without optimization. But it
This works, and I can't imagine how it might cause problems, but visual studio

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.