We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
prototype in json-maker.h is char* json_objOpen( char* dest, char const* name, size_t* remLen );
char* json_objOpen( char* dest, char const* name, size_t* remLen );
but the sample code is... dest = json_objOpen( dest, name );
dest = json_objOpen( dest, name );
also noticed the code looked suspiciously reactionary to buffer overflow at...
char buff[512]; int len = data_to_json( buff, &data ); if( len >= sizeof buff ) { fprintf( stderr, "%s%d%s%d\n", "Error. Len: ", len, " Max: ", (int)sizeof buff - 1 ); return EXIT_FAILURE; }
betting that issue was fixed, but the sample code wasn't updated.
The text was updated successfully, but these errors were encountered:
sample code
static size_t remLen; // MAX JSON String Count
struct header { int protocolVersion; int messageId; int stationId; }; struct data { struct header head; };
char* json_header( char* dest, char const* name, struct header const* head ) { dest = json_objOpen( dest, name, &remLen ); dest = json_int( dest, "protocolVersion", head->protocolVersion, &remLen ); dest = json_int( dest, "messageId", head->messageId, &remLen ); dest = json_objOpen( dest, "stationId", &remLen ); dest = json_int( dest, "value", head->stationId, &remLen ); dest = json_objClose( dest, &remLen ); dest = json_objClose( dest, &remLen ); return dest; } char* json_data( char* dest, char const* name, struct data const* data ) { dest = json_objOpen( dest, NULL, &remLen ); dest = json_header( dest, "header", &data->head ); dest = json_objClose( dest, &remLen ); return dest; } int data_to_json( char* dest, struct data const* data ) { char* p = json_data( dest, NULL, data, &remLen ); p = json_end( p, &remLen ); return p - dest; }
void main() { static struct data const data = { .head = { .protocolVersion = 1, .messageId = 2, .stationId = 185 } } char buff[512]; remLen = sizeof(buff); int len = data_to_json( buff, &data ); printf("%s \n", buff); return; }
result {"header":{"protocolVersion":1,"messageId":2,"stationId":{"value":185}}}
Sorry, something went wrong.
Seconded, @woogi1368's sample code fixes this issue and works, just tested it
No branches or pull requests
prototype in json-maker.h is
char* json_objOpen( char* dest, char const* name, size_t* remLen );
but the sample code is...
dest = json_objOpen( dest, name );
also noticed the code looked suspiciously reactionary to buffer overflow at...
betting that issue was fixed, but the sample code wasn't updated.
The text was updated successfully, but these errors were encountered: