Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsonObject.dump() #1732

Closed
mohammadrasekh68 opened this issue Aug 29, 2019 · 5 comments
Closed

JsonObject.dump() #1732

mohammadrasekh68 opened this issue Aug 29, 2019 · 5 comments
Labels
kind: bug state: needs more info the author of the issue needs to provide more details state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated

Comments

@mohammadrasekh68
Copy link

mohammadrasekh68 commented Aug 29, 2019

Hi
the problem is when we use dump() method, when it return the string literal from the JsonObject, JsonObject will be cleaned and initialized with random values!
so if i do something like this:
std::cout<<JsonObject.dump()<<endl; //printed :{"A":{"B":"7+NNf&&8Nf!","C":"12345678913456"}} std::cout<<JsonObject.dump()<<endl; //printed : nothing or some random characters

@gregmarr
Copy link
Contributor

That seems very unlikely unless JsonObject is a reference to an object that is destroyed at the end of the first statement. Do you have a full sample that demonstrates this issue?

@mohammadrasekh68
Copy link
Author

mohammadrasekh68 commented Aug 30, 2019

Json postData; postData = RequestTaskDescriptionJsonNode->getJsonNode(); //RequestTaskDescriptionJsonNode is a unique_ptr,returns a JsonObject // setup the POST data cout<<"post data Check: " <<postData.dump() .c_str()); // this one works fine curl_easy_setopt( ctx , CURLOPT_POSTFIELDS , postData.dump() .c_str()); // here data packet is empty
but this behavior does not happen always, I'm not facing it right now, even the code is the same!

@nlohmann
Copy link
Owner

nlohmann commented Sep 2, 2019

I would need to see more code to be able to assess this. Alternatively, can you run your code with Address Sanitizer to make sure the string you are parsing is valid?

@nlohmann nlohmann added the state: needs more info the author of the issue needs to provide more details label Sep 2, 2019
@mohammadrasekh68
Copy link
Author

mohammadrasekh68 commented Sep 9, 2019

@nlohmann unfortunately I cant run the program with Sanitizer
@kickunderscore
curl_easy_setopy is not a function but a macro
and one more thing is that we are using Dlt logging mechanism which is also a macro not a simple function.

complete code script is:

std::unique_ptr <CreateRequestJsonNode> RequestTaskDescriptionJsonNode=make_unique<CreateRequestJsonNode>();
std::unique_ptr <struct t_obu_task_description_request> request =std::make_unique<struct t_obu_task_description_request>();
	if(!m_vin.empty())
	{
		request->vin = m_vin;
	}

	if(!m_serialNumber.empty())
	{
		request->serial_number = m_serialNumber;
	}

	if(!m_password.empty())
	{
		request->obu_password = m_password;
	}

	if( RequestTaskDescriptionJsonNode->init(request))
	{
		fclose(localFile);
		DLTLOG(DLT_LOG_ERROR,"error on create task description request");
		return EXIT_DATA_ERROR;
	}
	postData = RequestTaskDescriptionJsonNode->getJsonNode();
	DLTLOG(DLT_LOG_INFO,"post data Check: " ,postData .c_str());
	curl_easy_setopt( ctx , CURLOPT_POSTFIELDS , postData .c_str());

@stale
Copy link

stale bot commented Oct 12, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Oct 12, 2019
@stale stale bot closed this as completed Oct 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug state: needs more info the author of the issue needs to provide more details state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated
Projects
None yet
Development

No branches or pull requests

3 participants