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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:27:20+00:00 2026-06-01T22:27:20+00:00

unsigned char* Data::getAddress(unsigned char* address) { strcpy((char*)address, (char*)this->_address); return (unsigned char*)address; } int main()

  • 0
unsigned char* Data::getAddress(unsigned char* address)
{
    strcpy((char*)address, (char*)this->_address);
    return (unsigned char*)address;
}

int main()
{
    Data d;
    d.makealinkedlisthere();
    while (d)
    {
       unsigned char address[256];
       printf("0x%08x \r\n",d.getAddress(address));
       d = d.getNext();
    }
    return 0;
}

It returns the first two (which is the same, and it should be different [can tell from the debugger]…) then crashes out.

It just makes a linked list. protected member Data* _next … a chain of them.

The unsigned char* is from Windows function VirtualQueryEx part of the MEMORY_BASIC_INFORMATION data structure it returns.

this->_address = (unsigned char*)meminfo->BaseAddress; // casted from void*

It is void*, but I see it converted to unsigned char* in other’s codes. In the debugger I can see it represented as a hex number.

D1: +    _address   0x7ffd5000 <Bad Ptr>    unsigned char * 
D1->_next:+  _address   0x7f6f0000 "áå•ú`©" unsigned char * 
D1->_next->_next+    _address   0x7ffb0000 " "  unsigned char *
  • 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-01T22:27:22+00:00Added an answer on June 1, 2026 at 10:27 pm

    MEMORY_BASIC_INFORMATION.Base Address is the location of the region of pages and not a string and there is no gurantee that it would be null terminated.
    From the MSDN site you can see the MEMORY_BASIC_INFORMATION structure

    typedef struct _MEMORY_BASIC_INFORMATION {
      PVOID  BaseAddress;
      PVOID  AllocationBase;
      DWORD  AllocationProtect;
      SIZE_T RegionSize;
      DWORD  State;
      DWORD  Protect;
      DWORD  Type;
    } MEMORY_BASIC_INFORMATION, *PMEMORY_BASIC_INFORMATION;
    

    To copy the data, you should use a memcpy with size = 255`.

    Looking back to your code, provided there is no other issues, changing it to

    PVOID Data::getAddress(PVOID address,size) {    
        memcpy((address, (void *)this->_address, size);
        address[size]=NULL;
        return address;
    }
    int main() {
        Data d;
        d.makealinkedlisthere();
        while (d) {
           unsigned char address[256];
           printf("Address: 0x%08x \n",d.getAddress((PVOID)address),sizeof(address));
           printf("Data: %s\n",(LPSTR)d.getAddress((PVOID)address),sizeof(address));
           d = d.getNext();
        }
        return 0;
    }
    

    should work

    Please also note, it would be safe to store RegionSize and to do a boundary check before memcpy.

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

Sidebar

Related Questions

#include <stdio.h> int main() { unsigned char data[1]; FILE *f = fopen(bill.jpg, rb); while
unsigned int *pMessageLength, MessageLength; char *pszParsePos; ... //DATA into pszParsePos ... printf(\nMessage Length\nb1: %d\nb2:
In c, are primitive data types such as int long char unsigned... all macros?
void callback(const unsigned char* data, int len) { unsigned char copydatahere; } data is
I have this array: unsigned char* data = CGBitmapContextGetData(cgctx); then I tried to get
I have an unsigned char* data with the following values, as seen while debugging
I have an std::vector<unsigned char> with binary data in. I just would like to
I have the following code int ParseData(unsigned char *packet, int len) { struct ethhdr
I'm trying to copy data into a unsigned char buffer within an array of
i have data (unsigned char data[480][640][4]) and two threads thisThread1FunctinIsCalledForExampleAbout50CallsPerSecond() { fill( data );

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.