node icon indicating copy to clipboard operation
node copied to clipboard

doc: clarify napi_get_value_string_* for bufsize 0

Open tniessen opened this issue 7 months ago • 2 comments

This edge case is ambiguous and it is unclear from the existing documentation what happens in this case.

tniessen avatar May 04 '25 12:05 tniessen

Review requested:

  • [ ] @nodejs/node-api

nodejs-github-bot avatar May 04 '25 12:05 nodejs-github-bot

I would rather change it to say that if bufsize is zero and the buf pointer is not null, then the string is not returned and not measured. To me the phrase "null-terminated if possible" sounds a bit ambiguous. We do always null-terminate string when we return it. We obviously cannot null terminate it when we do not return it. We do not return the string when either buf is null or the bufsize is zero. The buffer size must be big enough to fit the string and its null terminator.

vmoroz avatar May 04 '25 18:05 vmoroz

@tniessen , we discussed this PR in out last Node-API meeting on 5/9/2025. The team advised me to provide the text change suggestions instead of the general comment.

vmoroz avatar May 11 '25 23:05 vmoroz

Landed in acb3d922cb25c56308721ddcfa272d6b073bc5e6

nodejs-github-bot avatar May 12 '25 17:05 nodejs-github-bot