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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:35:15+00:00 2026-05-24T16:35:15+00:00

I get the above debugging problem from the function readString. I believe it has

  • 0

I get the above debugging problem from the function readString. I believe it has something to do with the way ‘start’ is defined in the function. The 0x07 in the array changes depending on the length of the following string. This string should say ‘testing’ in unicode.

int main(){
    char readbuffer[] = {0x07, 0x74, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67};
    char *buf = readbuffer;
    uint32_t *stringread = (uint32_t *) malloc(sizeof(uint32_t));
    *stringread = readString(buf);
    }

    uint32_t readString(char *buf)
    {
         uint32_t *start = (uint32_t *) malloc(sizeof(uint32_t));
         int len;

         len = protobuf_readVarint(buf, &buf);
         memcpy (&start, buf, len);
         buf += len;

         return start;

    }
  • 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-24T16:35:16+00:00Added an answer on May 24, 2026 at 4:35 pm

    Here

         memcpy (&start, buf, len);
    

    you are attempting to copy the contents of buf to &start (the address of the pointer variable start, that is in fact an address on the stack) instead of start (referring to the address of the memory buffer start is pointing to). This is what corrupts your stack.

    Apart from this, there are several other smaller issues in your code:

    • you have no bounds checking, so if len is > 4, memcpy will again silently write past the end of the memory block pointed to by start, corrupting memory;
    • you allocate a memory block within readString() which you never free, leading to a memory leak; if you are absolutely sure that len will never be more than 4, it would be simpler to use just a plain local variable:

       uint32_t start;
       ...
       memcpy (&start, buf, len);
      

      note that in this case it is correct to pass &start to memcpy!

    • buf += len will have no effect outside readString() since buf is passed by value, thus changes to it within the function affect only its local copy, not the original.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem Description: Occassionally when debugging, I get the following error. I'm using visual studio
I get the above error whenever I try and use ActionLink ? I've only
when I apply the tag above my methods I get the error Type System.Runtime.CompilerServices.Extension
How would you get a reference to an executing class several stack frames above
We get a large amount of data from our clients in pdf files in
I get a URL from a user. I need to know: a) is the
I get the following error when running my Visual Studio 2008 ASP.NET project (start
I get this error: Can't locate Foo.pm in @INC Is there an easier way
Note : This question has been re-asked with a summary of all debugging attempts
UPDATE As Mathias notes below, this exact problem has been reported and resolved here:

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.