1

I am getting image data from POST API using cpprestsdk in form of vector and then I am trying to convert it into unsigned char pointer for further processing.

Below is my code and it is working properly in ubuntu but in windows, the data is getting corrupted and as a result, I am not able to process image further.

string image_name = (string)http_get_vars["name"];
    int len;

    unsigned char *image_data = NULL;

    //reading binary data and storing it in a pointer
    request.extract_vector().then([image_name, &image_data, &len](vector<unsigned char> v) {
                utility::string_t ustring = {v.begin(),v.end()};
        image_data = (unsigned char *)ustring.c_str();
        len = ustring.size();
            }).wait();
Acorn
  • 24,970
  • 5
  • 40
  • 69
Harsh Shah
  • 11
  • 1
  • 2
    `image_data` is a dangling pointer to no-mans land once the `wait` returns. `ustring` ceases to exist after that, and with that, so goes the validity of `image_data`. if you're using it in a dereference context anywhere after that `wait`, you're invoking undefined behavior. – WhozCraig Sep 25 '19 at 15:14

0 Answers0