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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:37:10+00:00 2026-06-16T02:37:10+00:00

The following is a code snippet from my read from pipe function. This executes

  • 0

The following is a code snippet from my read from pipe function. This executes properly and verified that the data is got into buffer .

int readFrom(char *buffer)
{
int nread;

if((nread = read(readfd,buffer,100)) < 0)
{
    printf("\nerror in reading data from FIFO\n");
    return(-1);
}
buffer[nread]='\0';
return(0);
}

In the above example nread is less than 100 . I am using GCC-4.7.0.

We had an abstraction layer for the above function like below :

int pipe_input(char *parmPtr, int size)
{

char readMsg[100];


if( readFrom((char *)&readMsg) == -1)
  return ERROR;

if (strlen(readMsg) < 1)
{
    printf("Incorrect Input\n");
    return ERROR;
}
strncpy(parmPtr, readMsg, ((size < 100)?size:100));


return 0;

}

In the above function as well it was verified that read message is proper and parmptr is properly loaded with the value. But in the function Where i am trying to call pipe_input I am getting a sigsegv. This happens with GCC-4.7.0 but the same code compiled with GCC-4.2.4 executes fine. I verified the warnings, but there are no warning for the above. Any pointers would be highly helpful.

Below code snippet for calling pipe_input :

int Calling_func(void)
{
  char alpha[100] ;

  pipe_input(alpha,100);
  printf("alpha value is %s \r\n",alpha);
}

getting sigsegv at the print statement.

  • 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-16T02:37:11+00:00Added an answer on June 16, 2026 at 2:37 am

    You have off-by-one errors in your code. Your array has 100 elements, but you’re not taking NULL-termination into account:

    strncpy(parmPtr, readMsg, ((size < 100)?size:100));
    

    and:

    buffer[nread]='\0';
    

    The last element is buffer[99] (since array indices start from 0, not 1,) but you can write to buffer[100]. This can result in a segfault.

    You should probably declare all arrays with a size of 101 instead and see if it helps. If you’re on Linux, you should also run your program in Valgrind; it can tell you exactly how the segfault occurred.

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

Sidebar

Related Questions

I have written the following code snippet to read data from the database :
From this site: http://www.toymaker.info/Games/html/vertex_shaders.html We have the following code snippet: // transformations provided by
I'm using the following code to read data from an XML file stored in
From an online notes, I read the following java code snippet for reversing a
The following code snippet is from The Official GNOME 2 Developer's Guide : GMemChunk
From the book Groovy and Grails recipes I'm using the following code snippet: String
I have the following very simple code snippet which is loaded from a separate
I have the following snippet from my code: switch ($extention) { case gif: $src
Hey all, the following is a snippet of code taken from the unix ptx
following snippet is from rails code def rescue_from(*klasses, &block) options = klasses.extract_options! unless options.has_key?(:with)

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.