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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:46:07+00:00 2026-05-30T17:46:07+00:00

I posted a problem and got an answer here . Here is the code

  • 0

I posted a problem and got an answer here.
Here is the code which i debugged on VC2010. I get the run time error shown at the end.
What is wrong with usage of sdir?

#include<iostream>
#include<stdlib.h>

#include<windows.h>
void make_dir(int depth, char *dir) {
  if (depth < 3) {

    CreateDirectoryA (dir,NULL); 

    for (int i = 0; i < 10; i++) {
       char *sdir= (char*)malloc(strlen(dir+10)); // XXX 10?
        strcpy(sdir, dir);
        sprintf(sdir + strlen(sdir), "\\%d", i); 
        printf("%s\n", sdir);
        CreateDirectoryA(sdir,NULL);
        make_dir(depth + 1, sdir);
        free(sdir);
    }   
  }     
}

int  main()
{
    make_dir(0,"dir");
    return 1;
}

The error is:

HEAP[mkdir.exe]: Heap block at 004114E8 modified at 00411514 past requested size of 24
Windows has triggered a breakpoint in mkdir.exe.

This may be due to a corruption of the heap, which indicates a bug in
mkdir.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while mkdir.exe has
focus.

The output window may have more diagnostic information. The program
‘[3008] mkdir.exe: Native’ has exited with code 0 (0x0).

  • 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-30T17:46:08+00:00Added an answer on May 30, 2026 at 5:46 pm

    The most glaring error I see is that you’re adding 10 to the pointer being passed to strlen; this will either read memory outside of the string if the string is less than 10 characters long, or subtract 10 from the length of the string otherwise. You probably want to be adding 10 to the result of strlen, not the input.

    In other words, move the ) after the +10 to before the +10.

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

Sidebar

Related Questions

I got this itching problem and I cant get the code to work How
I have already posted my this problem another time but i have not got
I have a RichTextBox which contains links posted by the users. The problem is
I call addNotify() method in class that I posted here. The problem is, that
I couldn't really word the title very well, but here's my problem: I've got
i have already posted my issue in SO and got an answer but i
this is a rephrasing of a question I posted yesterday. I got an answer
a couple of days ago, I posted here and got a great response on
Someone posted something similar but it didn't really solve the problem. I want to
We have a problem in a specific server. All plus signs posted to the

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.