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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:12:54+00:00 2026-06-01T10:12:54+00:00

I am working with snmp and the requests->requestvb->val.string function returns me a u_char* and

  • 0

I am working with snmp and the requests->requestvb->val.string function returns me a u_char* and I am trying to store that into a char[255].

u_char newValue = *(requests->requestvb->val.string)
char myArray[255];

I have tried a few approaches to copy the contents of newValue into myArray but everything seems to segfault. What am I doing wrong?

I have tried
memcpy(myArray, newValue);

Another attempt strncopy(myArray, newValue, sizeof(myArray));

What am I doing wrong?

  • 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-01T10:12:56+00:00Added an answer on June 1, 2026 at 10:12 am

    Your newValue is of type char, and for all intents and purposes, your myArray is of type char*.

    First off, I’m going to assume that you’re using memcpy correctly, and that you’re passing in 3 parameters instead of 2, where the 3rd parameter is the same as the one you use in strncpy.

    When you try using strncpy or memcpy, you’re going beyond the one character “limit” in newValue when attempting to copy everything to myArray.

    The fix should be quite simple:

    u_char* newValue = requests->requestvb->val.string;
    

    Once you’ve done that, this should work. Of course, that’s assuming that the size of myArray is in fact greater than or equal to 255 🙂

    As a side note (and this should go without saying), please make sure that your myArray has a null terminating character at the end if you ever plan on printing it. Not having one after performing copy operations, and then trying to print is a very common mistake and can also lead to seg faults.

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

Sidebar

Related Questions

I'm working on a implementing a SNMP into a GWT project. I need to
Working on calling a C function from my asm project. I'm trying to push
I am working on an embedded TCP/IP4 stack and HTTP/SNMP/SMTP stuff. It functionally works
Working on a bunch of forms at the moment and I'm finding that I
Working on a website that has Employee and Branch entities, using a database table
Working on a movie website and would love to find an API that I
I have a 3rd-party protocol module (SNMP) that is built on top of asyncore.
I am specifically trying to read data from an SNMP port in python using
Working on an extension that use the new experimental devtools apis. How do you
I am working on a problem in SNMP extension agent in windows, which is

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.