From: Junio C Hamano Date: Mon, 21 Sep 2026 22:34:43 GMT Subject: Re: [PATCH 6/6] strbuf-safe: add init and release methods Message-ID: In-Reply-To: Junio C Hamano writes: > "Derrick Stolee via GitGitGadget" 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.