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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:40:21+00:00 2026-05-28T14:40:21+00:00

The following is a segment from a code which supposes to test communication with

  • 0

The following is a segment from a code which supposes to test communication with a server and obtain a picture from it:

bool testPICcomm(){
    Poco::Logger &logger = Poco::Logger::get("PictureTester");
    logger.setLevel(Poco::Message::PRIO_DEBUG);
    HttpClient* h = new HttpClient(host, 80);
    std::map<std::string, std::string> headers;
    Poco::UTF8Encoding utf;
    Encoder encoder(utf);


     h->connect();
     h->sendHttpRequest(askForPic,"","",0,0);
     if((h->getHttpHeaders(headers, encoder)) == false)
         {
         logger.debug("Couldn't Retrieve Headers "+ false);
         h->close();
         return false;
         }
     logger.debug("got headers");

     //get head data
     std::string mime = headers["Content-Type"];
     logger.debug("mime type:"  + mime);
     logger.debug("length string: "  + std::string((headers["Content-Length"]).c_str()));
     int length= atoi((headers["Content-Length"]).c_str());
     logger.debug("pic length:" + length);
...

I am using eclipse on linux (eclipse doesn’t function too well so im working only on the console).

Now by following logger messages i deduce that atoi (look at the end of the code) causes the segmentation fault.

Which is really weird considering that another function testXMLcomm works fine and it looks similar.

i included stdio and stdlib ofcourse.

Please Help!!!

  • 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-28T14:40:23+00:00Added an answer on May 28, 2026 at 2:40 pm

    I expect the crash is in the line logger.debug("pic length:" + length);. You’ve added an integer offset length to a pointer-to-string-literal, and come up with an address in no-man’s land.

    You probably wanted to write something like:

    ostringstream ss("pic length: ");
    ss << length;
    logger.debug(ss.str());
    

    Or logger.debug("pic length: " + boost::lexical_cast<string>(length));, or C++11 has std::to_string(length).

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

Sidebar

Related Questions

I have the following code segment in which I'm getting error using (var session
I were asked to analyze an assembly code, which was generated from following c++
Having trouble with the following segment of code. I'm getting a parameter count mismatch.
I have two identical byte arrays in the following segment of code: /// <summary>
I created a new project with the following code segment: char* strange = (Strange??);
I have a controller class as in the following code segment: @Controller public class
Consider the following C code segments. Segment 1: char * getSomeString(JNIEnv *env, jstring jstr)
I've got the following C# code segment that takes a list, finds objects that
I am trying to implement a linked list using following code, I got segment
I have the following segment of code that someone else has written, and that

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.