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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:41:09+00:00 2026-05-23T02:41:09+00:00

I’ve been looking into this problem for hours and tried all sorts of things,

  • 0

I’ve been looking into this problem for hours and tried all sorts of things, but everything results in the same – a SIGSEGV (from gdb; according to VC debug it’s a stack overflow…) at the point when a static class method gets called.

The culprit code:

void LEHelper::copySinglePath (std::string from_path, std::string to_path)
{
    // first check if this path is a file or folder
    if (!folderExists(from_path)) // is a file
    {
        FILE *fp = fopen(from_path.c_str(), "rb");
        FILE *tp = fopen(to_path.c_str(), "wb");

        if (fp && tp)
        {
            // read 1MB chunks from the file and copy to the new destination until finished
            LEuchar bytes[1048576];

            while (!feof(fp))
            {
                size_t read_num = fread(bytes, sizeof(LEuchar), 1048576, fp);
                fwrite(bytes, sizeof(LEuchar), read_num, tp);
            }
        }

        if (fp)
            fclose(fp);
        if (tp)
            fclose(tp);
    }
    else // is a folder
    {
        // make a new directory at the "to" path to copy files into
    #if defined(LE_OS_OSX)
        mkdir(to_path.c_str(), S_IRWXO | S_IRWXG | S_IRWXU);
    #elif defined(LE_OS_WIN)
        mkdir(to_path.c_str());
    #endif

        // need to get all contents and recursively perform this method with correct pathing
        LEArray<std::string> contents = getContentsOfDirectoryUsingFilter(from_path, LEH_DIR_BOTH);
        std::string *current;

        contents.initEnumerator();
        while ((current = contents.nextObject()))
        {
            // first build the current file or folder path (and new path)
            std::string current_path = from_path;
            std::string new_path = to_path;

            if (current->length() > 0)
            {
                current_path += LE_PATH_SEPARATOR + *current;
                new_path += LE_PATH_SEPARATOR + *current;
            }

            // then copy as necessary --- this is where things go bad ---
            copySinglePath(current_path, new_path);
        }
    }
}

And the call stack is:

#0 00000000 0x0040db8a in _alloca() (??:??)
#1 00403888 LEHelper::copySinglePath(from_path=..., to_path=...) 
#2 00403AD1 LEHelper::copySinglePath(from_path=..., to_path=...) 
#3 00403C8C LEHelper::copyPath(existing_path=..., new_path=..., ow=true) 
#4 00402CD3 main(argc=1, argv=0x992c10) 

In the program I’m testing this in it is called once successfully reaching the recursive point with all values correct (I’ve been checking string values with printf), but on calling copySinglePath() within it fails. Since the call stack is so small I find it hard to believe this is actually a stack overflow from too many recursions… but my understanding could be wrong.

In my researching for an answer I read most segmentation faults are caused by pointer issues, so I’ve tried changing the arguments for copySinglePath() to be pointers, allocating the passed in strings on the heap with new (so I have control over allocation, etc.), but that didn’t make any difference.

Also odd is that this exact same code runs perfectly on OSX. Because of this, I thought there may be something somehow wrong with my mingw setup so I’ve reinstalled it with the latest mingw-get and still nothing different. I even had the thought that my Visual Studio install files could somehow be being used (includes that is), so temporarily changed their folder in an attempt to make sure, and it still compiled etc. so that shouldn’t be it…

I’m at a complete loss now as to why this is happening. If anyone has any thoughts on what I might be doing wrong, please…

Thanks to all in advance

  • 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-23T02:41:10+00:00Added an answer on May 23, 2026 at 2:41 am

    You may well need to lower the size of your chunks, or alloc them on the heap. The call stack is very small, but the stack includes local variables. The Windows stack is, by default, only 1MB from memory whereas the Unix stack is 8MB. Allocating a 1MB array off this stack is instant overflow. You need to alter your linker settings to permit a larger stack size.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have been unable to fix a problem with Java Unicode and encoding. The
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all

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.