Skip to content

docs: clarify return contracts for parse_hex4 and cJSON_ReplaceItemInArray#1056

Open
JIgar-maheshwari-dev wants to merge 1 commit into
DaveGamble:developfrom
JIgar-maheshwari-dev:docs/clarify-api-contracts
Open

docs: clarify return contracts for parse_hex4 and cJSON_ReplaceItemInArray#1056
JIgar-maheshwari-dev wants to merge 1 commit into
DaveGamble:developfrom
JIgar-maheshwari-dev:docs/clarify-api-contracts

Conversation

@JIgar-maheshwari-dev

@JIgar-maheshwari-dev JIgar-maheshwari-dev commented Jul 22, 2026

Copy link
Copy Markdown

Fixes #1007

Overview

This PR adds clarifying documentation comments for parse_hex4 and cJSON_ReplaceItemInArray to document ambiguous return values and error conditions without introducing breaking API changes.


Changes Included

1. Document parse_hex4 Dual-Meaning Return (cJSON.c)

  • Added a function header comment explaining that returning 0 serves a dual purpose:
    • Valid Parse: The input sequence represents 0x0000 (e.g., \u0000).
    • Invalid Parse: An invalid hexadecimal digit was encountered.
  • Helps future maintainers understand why callers must rely on pointer progression or input checks to distinguish 0x0000 from parsing failures.

2. Document cJSON_ReplaceItemInArray Out-of-Range Contract (cJSON.h & cJSON.c)

  • Added doc comments to the declaration in cJSON.h and definition in cJSON.c.
  • Clarified that returning cJSON_False (0) covers both NULL arguments and silent failures when an index (which) is out of bounds or negative.

Motivation

These edge cases were previously undocumented, making silent cJSON_False returns or 0 sentinel values difficult to interpret without inspecting internal source code. Adding these comments improves API clarity while preserving full backward compatibility.

Verification

  • Documentation-only change; no code behavior or binary output was modified.
  • All existing unit tests continue to pass.

- Add doc comment above parse_hex4 explaining that returning 0 represents both valid 0x0000 and parse failures.
- Document cJSON_ReplaceItemInArray return behavior in cJSON.h and cJSON.c, noting that returning cJSON_False covers both NULL inputs and out-of-bounds indices.

Signed-off-by: JIgar-maheshwari-dev <maheshwarijigar656@gmail.com>
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