From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 01F4A1F87E for ; Mon, 13 Nov 2023 13:15:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1699881356; bh=bWRfPHw4I+MtKQLIbAQG6USUTP7BhjKUKycAUHNPPB0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=HlSFkdFiwtoJV+sRXhQe3xjcaqJAN6cvF9Rd+oTHYri+8vQ+K9sunui2pxs1WHZqu KSuDazm0080JgRMeHjaSuq/G7SkLC0J6UDJe3rrhlXrFtXUuXpQcxHytbkQb5ySGF2 nsrre7aX4UxtY6y4ztB1Ry+B5+ImTpVlygoBNs3E= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 15/18] xap_helper: better variable naming for key buffer Date: Mon, 13 Nov 2023 13:15:48 +0000 Message-Id: <20231113131551.843230-16-e@80x24.org> In-Reply-To: <20231113131551.843230-1-e@80x24.org> References: <20231113131551.843230-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We'll use `kbuf' for the search object key, since we already use the `fbuf' term in `struct fbuf'. This also adds an extra check for open_memstream(3) failures in case of ENOMEM. --- lib/PublicInbox/xap_helper.h | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/lib/PublicInbox/xap_helper.h b/lib/PublicInbox/xap_helper.h index 1380ffd0..0a652abd 100644 --- a/lib/PublicInbox/xap_helper.h +++ b/lib/PublicInbox/xap_helper.h @@ -762,7 +762,7 @@ static void dispatch(struct req *req) union { struct srch *srch; char *ptr; - } fbuf; + } kbuf; char *end; FILE *kfp; struct srch **s; @@ -776,8 +776,9 @@ static void dispatch(struct req *req) } if (!req->fn) ABORT("not handled: `%s'", req->argv[0]); - kfp = open_memstream(&fbuf.ptr, &size); - // write padding, first + kfp = open_memstream(&kbuf.ptr, &size); + if (!kfp) err(EXIT_FAILURE, "open_memstream(kbuf)"); + // write padding, first (contents don't matter) fwrite(&req->argv[0], offsetof(struct srch, paths), 1, kfp); // global getopt variables: @@ -824,26 +825,24 @@ static void dispatch(struct req *req) default: ABORT("bad switch `-%c'", c); } } - if (ferror(kfp) | fclose(kfp)) + if (ferror(kfp) | fclose(kfp)) /* sets kbuf.srch */ err(EXIT_FAILURE, "ferror|fclose"); // likely ENOMEM - fbuf.srch->db = NULL; - fbuf.srch->qp = NULL; - fbuf.srch->paths_len = size - offsetof(struct srch, paths); - if (fbuf.srch->paths_len <= 0) { - free_srch(fbuf.srch); + kbuf.srch->db = NULL; + kbuf.srch->qp = NULL; + kbuf.srch->paths_len = size - offsetof(struct srch, paths); + if (kbuf.srch->paths_len <= 0) ABORT("no -d args"); - } - s = (struct srch **)tsearch(fbuf.srch, &srch_tree, srch_cmp); + s = (struct srch **)tsearch(kbuf.srch, &srch_tree, srch_cmp); if (!s) err(EXIT_FAILURE, "tsearch"); // likely ENOMEM req->srch = *s; - if (req->srch != fbuf.srch) { // reuse existing - free_srch(fbuf.srch); + if (req->srch != kbuf.srch) { // reuse existing + free_srch(kbuf.srch); } else if (!srch_init(req)) { - assert(fbuf.srch == *((struct srch **)tfind( - fbuf.srch, &srch_tree, srch_cmp))); - void *del = tdelete(fbuf.srch, &srch_tree, srch_cmp); + assert(kbuf.srch == *((struct srch **)tfind( + kbuf.srch, &srch_tree, srch_cmp))); + void *del = tdelete(kbuf.srch, &srch_tree, srch_cmp); assert(del); - free_srch(fbuf.srch); + free_srch(kbuf.srch); goto cmd_err; // srch_init already warned } try {