Skip to content

Adding basic support for length delimited strings#889

Open
ste-lam wants to merge 1 commit intoDaveGamble:masterfrom
ste-lam:string_with_length
Open

Adding basic support for length delimited strings#889
ste-lam wants to merge 1 commit intoDaveGamble:masterfrom
ste-lam:string_with_length

Conversation

@ste-lam
Copy link
Copy Markdown

@ste-lam ste-lam commented Aug 31, 2024

This PR adds basic support for applications that do not use c-strings but length delimited strings.
Here you need to create a temporary c-string copy to transfer the string to cjson.

To avoid this superfluous temporary copy, this PR adds two new public functions (with new tests):

  • cJSON_CreateRawWithLength: create a cJSON_Raw from a length delimited input string
  • cJSON_CreateStringWithLength: create a cJSON_String from a length delimited input string

JSON_AddXToObject functions have intentionally not been added.

Nullbytes within length-limited strings are still interpreted as null-termination, which is limitation as long as cjson uses c-strings internally.

@ste-lam ste-lam changed the base branch from master to develop September 2, 2024 20:23
@ste-lam ste-lam changed the base branch from develop to master September 2, 2024 20:24
@ste-lam ste-lam force-pushed the string_with_length branch 4 times, most recently from e432da0 to 755622d Compare April 23, 2025 14:22
 - cJSON_CreateRawWithLength: create a cJSON_Raw from a length limited input string
 - cJSON_CreateStringWithLength: create a cJSON_String from a length limited input string
@ste-lam ste-lam force-pushed the string_with_length branch from 5c89f9b to f3a3201 Compare October 25, 2025 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant