Re: [PATCH 6/6] strbuf-safe: add init and release methods
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Sep 21, 2026, 22:34 UTC
- Message-ID
- <xmqq1pamkzcs.fsf@gitster.g>
- In-Reply-To
- <xmqqld8ul1ny.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
Show 22 quoted lines
> "Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
>> +int jw_release(struct json_writer *jw)
>> {
>> - strbuf_release(&jw->json);
>> - strbuf_release(&jw->open_stack);
>> + enum safe_result result = SUCCESS;
>> +
>> + /* attempt both removals without short-circuiting. */
>> + result = sstrbuf_release(&jw->json) || result;
>> + result = sstrbuf_release(&jw->open_stack) || result;
>> +
>> + return result;
>> }
>
> This is puzzling in a few ways.
> If we mean "enum safe_result" is an enumeration of different kinds
> of errors, then the "result" variable and the returned value from
> ...
> On the other hand, if we mean "enum safe_result" is an enumeration
> of bitmasks, each bit representing different kind of error, then
> ...I forgot the third possibility. Regardless of which interpretation of "enum safe_result" we use, if jw_release() is designed to say "0 for success, non-zero for failure", then almost as written but declaring "result" as a plain "int"
int result = 0;
result = sstrbuf_release(&jw->json) || result;
result = sstrbuf_release(&jw->open_stack) || result;return result;
would probably make sense, even though the "|| result" construct is a bit unusual in C.
Thanks.