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

  • Home
  • SEARCH
  • 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 8449785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:48:17+00:00 2026-06-10T10:48:17+00:00

I’m resizing an array. The resize (doubling the size) appears to work correctly, but

  • 0

I’m resizing an array. The resize (doubling the size) appears to work correctly, but when I send more text into the resized array, when it reaches what would have been the limit of the array before it was resized, I get a “Debug Assertion Failed! Expression: (L”Buffer is too small” && 0)” error. I’ve tried it a few different ways, always with the same result.

    static int ReadBufferSize, totalChars;    
    static char *ReadBuffer = NULL;
    ReadBuffer = (char *)malloc(ReadBufferSize);

    ...

    //Double buffer size.
    if((float)totalChars > (0.75f) * (float)ReadBufferSize)
    {
        char *tempBuffer = NULL;
        tempBuffer = (char *)malloc(2 * ReadBufferSize); 
        if(tempBuffer == NULL)
            free(tempBuffer);
        else
        {
            memcpy(tempBuffer,ReadBuffer,strlen(ReadBuffer)+1);
            free(ReadBuffer);
            ReadBuffer = tempBuffer;
            tempBuffer = NULL;
            ReadBufferSize *= 2;
        }
    }

For my testing, ReadBufferSize has been set initially to 85 characters. After the code resizing the array is executed, the text in ReadBuffer is still displayed on the screen. I type more characters and they are sent into the array, and from there, displayed on the screen. But when the number of characters reaches 85 characters, I get the “Debug Assertion Failed! Expression: (L”Buffer is too small” && 0)” error, when there should now be space for 170 characters. I’ve also tried the following.

//Double buffer size.
if((float)totalChars > (0.75f) * (float)ReadBufferSize)
{
    char* temp = 0;
    temp = new char[2 * ReadBufferSize];
    for(unsigned int i = 0; i < strlen(ReadBuffer); i++)
        temp[i] = ReadBuffer[i];
    temp[strlen(ReadBuffer)] = '\0';
    delete[] ReadBuffer;
    ReadBuffer = temp;
    temp = 0;
    ReadBufferSize *= 2;
}

I’ve also tried:

malloc(2 * ReadBufferSize * sizeof(char));

and:

strcpy_s(tempBuffer, strlen(ReadBuffer)+1, ReadBuffer);

Many thanks.

  • 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-10T10:48:19+00:00Added an answer on June 10, 2026 at 10:48 am

    I figured it out. I was about to post some more of my code to give you more information when I noticed the problem. I had a “pageSize” variable that I had been using for the size of the array. Then when I wanted to start dynamically changing the size, I separated the array size from the page size by creating the “ReadBufferSize” variable. Unfortunately, I still had “pageSize” in the segment of code where I was putting characters into the array:

    strcat_s(ReadBuffer, pageSize, keystroke);
    

    I’ve now changed it to

    strcat_s(ReadBuffer, ReadBufferSize, keystroke);
    

    and everything seems to be working. Thanks to everyone for taking the time to look at this. I was fixated on the idea that the problem must be in the section of code for resizing the array, not elsewhere.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I have a reasonable size flat file database of text documents mostly saved in
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from

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.