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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:50:22+00:00 2026-06-12T23:50:22+00:00

I have to work and create often matrices(I have to use pointers) so I

  • 0

I have to work and create often matrices(I have to use pointers) so I made a function in C++ to allocate space for them and also make sure that the last value is set to NULL.
The application drops this error(glibc detected: memory curruption) in a specific case. Here is the code:

template<typename T> T *allocate(int size) {
    T *temp = new T[size];
    temp[size] = (T) NULL;
    return temp;
}

This works:

unsigned char *tmp = allocate <unsigned char> (10);

But this one drops the error:

unsigned char **tmp = allocate <unsigned char *> (10);

That would be the equivalent of:

unsigned char **tmp = new unsigned char *[10];
tmp[10] = (unsigned char *) NULL;

Which is good. Why would it drop me this error?

Update: Thanks for the responses. I am so blind. That’s one bug. But the problem of the crash was from another part of the code but also because I was adding NULL outside the allocated space of the array.

  • 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-12T23:50:23+00:00Added an answer on June 12, 2026 at 11:50 pm

    You can’t do this:

    temp[size] = (T) NULL;
    

    Size in this case is indexing the memory position AFTER the last one you allocated, change it for this:

    temp[size-1] = (T) NULL;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

At work, I often have to deal with 3rd party libraries, which make heavy
Today i have been interested in answers on this: where you create your work
I have the this code that will create excel file and work sheet then
I have a script that parse the database and create php classes to work
I work with Oracle 11g. I have one table: create table test (one number(2),
I created a chrome extension to make things easier at work. We have a
I often have to work with fragile legacy websites that break in unexpected ways
I have a page that needs to create dynamic form fields as often as
I want to be able to do Artist.case_insensitive_find_or_create_by_name(artist_name) [1] (and have it work on
Say I have two classes created work and workItem. CWorker *work = new CWorker();

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.