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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:52:19+00:00 2026-05-22T18:52:19+00:00

I have some trouble running a program that uses this function static int upload_build_buffer(char

  • 0

I have some trouble running a program that uses this function

static
int upload_build_buffer(char **upload_buffer,int seq_n, char* buffer) {

    char *up_buffer = NULL;
    assert(buffer);
    assert(upload_buffer);

    *upload_buffer = NULL;
    *upload_buffer = malloc((SIZE_SEQ_N+strlen(buffer)+1) * sizeof(char));
    if(!(*upload_buffer))
        return 1;
    up_buffer = malloc((SIZE_SEQ_N+strlen(buffer)+1) * sizeof(char));
    if(!(up_buffer))
        return 1;

    /* prints formatted sequence number in its string */
    snprintf((*upload_buffer), SIZE_SEQ_N+1, "%5d", seq_n);
    (*upload_buffer)[SIZE_SEQ_N] = 0;


    /* creates payload -> buffer = seq_number + buffer */
    strncpy(up_buffer,strncat((*upload_buffer), buffer, SIZE_PAYLOAD), SIZE_SEQ_N + SIZE_PAYLOAD);

    free(*upload_buffer);
    *upload_buffer = up_buffer;
    return 0;
}

at runtime I get this error if I execute this function more than once:

malloc.c:3096: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) == 0)' failed.

the call of function is the following:

/* builds buffer to send */
if(seq_numbered_buffer) {
    free(seq_numbered_buffer);
    seq_numbered_buffer = NULL;
}
if(upload_build_buffer(&seq_numbered_buffer, seq_n, buffer))
    return 1;

moreover if I run valgrind I get:

==2832== Invalid write of size 1
==2832==    at 0x4026FBF: strncpy (mc_replace_strmem.c:339)
==2832==    by 0x80490F7: upload_build_buffer (uftp_client.c:189)
==2832==    by 0x8049606: client_upload_file (uftp_client.c:397)
==2832==    by 0x804A30F: data_connection_proc (uftp_client.c:882)
==2832==    by 0x804AE4B: main (uftp_client.c:1214)
==2832==  Address 0x419b0c4 is 0 bytes after a block of size 52 alloc'd  
==2832==    at 0x4025BD3: malloc (vg_replace_malloc.c:236)
==2832==    by 0x8049062: upload_build_buffer (uftp_client.c:174)
==2832==    by 0x8049606: client_upload_file (uftp_client.c:397)
==2832==    by 0x804A30F: data_connection_proc (uftp_client.c:882)
==2832==    by 0x804AE4B: main (uftp_client.c:1214)
==2832== 
==2832== Invalid write of size 1
==2832==    at 0x4026FCB: strncpy (mc_replace_strmem.c:339)
==2832==    by 0x80490F7: upload_build_buffer (uftp_client.c:189)
==2832==    by 0x8049606: client_upload_file (uftp_client.c:397)
==2832==    by 0x804A30F: data_connection_proc (uftp_client.c:882)
==2832==    by 0x804AE4B: main (uftp_client.c:1214)
==2832==  Address 0x419b0c5 is 1 bytes after a block of size 52 alloc'd
==2832==    at 0x4025BD3: malloc (vg_replace_malloc.c:236)
==2832==    by 0x8049062: upload_build_buffer (uftp_client.c:174)
==2832==    by 0x8049606: client_upload_file (uftp_client.c:397)
==2832==    by 0x804A30F: data_connection_proc (uftp_client.c:882)
==2832==    by 0x804AE4B: main (uftp_client.c:1214)

I have no idea how to debug this code..

  • 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-22T18:52:20+00:00Added an answer on May 22, 2026 at 6:52 pm

    The Valgrind output tells you pretty much everything- you wrote past the end of the buffer in a strncpy call. There’s only one strncpy call in the function. Thus, logically, you messed up your buffer sizes or strncpy arguments.

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

Sidebar

Related Questions

I'm migrating to Nhibernate 2.0 GA but have some trouble with setting cache expirations
I am developing a small windows app, but have some trouble deciding whether to
I'm currently working on project with Haskell, and have found myself some trouble. I'm
I am having some trouble with the Google Maps API . I have an
I have created some rounded navigation tabs using CSS and am having trouble when
I have some UI in VB 2005 that looks great in XP Style, but
We have some input data that sometimes appears with &nbsp characters on the end.
I have some classes layed out like this class A { public virtual void
I have a hosted site and I'm having trouble configuring Joomla (running Joomla +
I have a script that appends some rows to a table. One of 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.