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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:38:37+00:00 2026-06-06T12:38:37+00:00

#define BUF_SIZE 10 char *html = foo:baa\r\nxxx:yyyy:\r\nLocation:………………………………….\r\Connection:close\r\n\r\n; char *p = (char*)html, *buf, *pbuf, *tbuf;

  • 0
#define BUF_SIZE 10

char *html = "foo:baa\r\nxxx:yyyy:\r\nLocation:........................................\r\Connection:close\r\n\r\n";
char *p = (char*)html, *buf, *pbuf, *tbuf;
int buf_size = BUF_SIZE, hsize = 0;

 if((buf = malloc(buf_size)) == NULL) FAILED("NO MEMORY!\n");
   pbuf = buf;

    while(*p != '\0' && *(p + 1) != '\r' && *(p + 2) != '\n') {
                    if((hsize + 1) >= buf_size) {
                        printf("Do realloc!\n");
                        buf_size += BUF_SIZE + 2; 
                        tbuf = realloc(buf, buf_size); // BUF_SIZE 
                        if(tbuf != NULL) {
                            buf = tbuf;
                        } else {
                            printf(" NO MEMORY!\n");
                            exit(1);
                        }
                    }

                    *pbuf ++= *p++, hsize ++;
            }

But it give an

Do realloc!
Do realloc!
Stack trace:
Frame     Function  Args
0022A814  7798EFA3  (000000FC, 0000EA60, 00000000, 0022A948)
0022A828  7798EF52  (000000FC, 0000EA60, 000000A4, 0022A924)
0022A948  610DB059  (00000000, 00000001, 0022A978, 0000000C)
0022AA38  610D841E  (00000000, 61102908, 003B0023, 00230000)
0022AA98  610D88EE  (20038878, 0000000C, 0022AAC8, 00000006)
0022AB48  610D8A40  (00000E3C, 00000006, 00000001, 20010340)
0022AB68  610D8A6C  (00000006, 0022CE80, 0022ABD4, 20038883)
0022AB98  610D8CF5  (004031AA, 20010340, 0022ABE8, 61138596)
20010348  6110F935  (73756A2E, DF0DF02E, 200000C8, 00000000)

I have no idea how to fix this! Actually, I am not sure that it’s a really segmentation fault.

  • 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-06T12:38:38+00:00Added an answer on June 6, 2026 at 12:38 pm

    You have two fatal issues:

    1. pbuf is assigned the value of buf at init but then is never updated. realloc is not guaranted to return the same address after malloc (and the subsequent realloc calls).

    2. You are overflowing pbuf here before calling the required realloc:

      *pbuf ++= *p++, hsize ++;

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

Sidebar

Related Questions

#define HISTORY_SIZE 50 #define INPUT_SIZE 512 /*Max input size*/ char input[INPUT_SIZE]; /*Holding user input
In kernel space, I have the following: char * myData[MAX_BUF_SIZE][2]; I need to define
int str_len = read(m_events[i].data.fd, buf, BUF_SIZE); I have this and I read data into
I have this struct; #define BUFSIZE 10 struct shared_data { pthread_mutex_t th_mutex_queue; int count;
(define (lcs lst1 lst2) (define (except-last-pair list) (if (pair? (cdr list)) (cons (car list)
#define MAX 100 struct bs{ int ab; int ac; }be; struct s{ be b;
#define __HAVE_ARCH_STRCPY What's the meaning of __HAVE_ARCH ? I'm not a native speaker and
I define a tabs using JQuery <div id=tabs> <ul> <li><a href=#tabs-1>Tab 1</a></li> <li><a href=#tabs-2>Tab
Ext.define('DigitalPaper.controller.Documents', { extend: 'Ext.app.Controller', views: ['Documents'], stores: ['Documents'], models: ['Documents'], init: function() { console.log('[OK]
I define a 'block' of text as all lines between start of file, newline

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.