From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE2F0C352A3 for ; Tue, 11 Feb 2020 20:23:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BCD8B20708 for ; Tue, 11 Feb 2020 20:23:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731816AbgBKUXT (ORCPT ); Tue, 11 Feb 2020 15:23:19 -0500 Received: from correo.us.es ([193.147.175.20]:39196 "EHLO mail.us.es" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731076AbgBKUXT (ORCPT ); Tue, 11 Feb 2020 15:23:19 -0500 Received: from antivirus1-rhel7.int (unknown [192.168.2.11]) by mail.us.es (Postfix) with ESMTP id 0B3BFEBACC for ; Tue, 11 Feb 2020 21:23:19 +0100 (CET) Received: from antivirus1-rhel7.int (localhost [127.0.0.1]) by antivirus1-rhel7.int (Postfix) with ESMTP id F08ABDA709 for ; Tue, 11 Feb 2020 21:23:18 +0100 (CET) Received: by antivirus1-rhel7.int (Postfix, from userid 99) id E6222DA705; Tue, 11 Feb 2020 21:23:18 +0100 (CET) Received: from antivirus1-rhel7.int (localhost [127.0.0.1]) by antivirus1-rhel7.int (Postfix) with ESMTP id F3EA4DA702; Tue, 11 Feb 2020 21:23:16 +0100 (CET) Received: from 192.168.1.97 (192.168.1.97) by antivirus1-rhel7.int (F-Secure/fsigk_smtp/550/antivirus1-rhel7.int); Tue, 11 Feb 2020 21:23:16 +0100 (CET) X-Virus-Status: clean(F-Secure/fsigk_smtp/550/antivirus1-rhel7.int) Received: from salvia.here (unknown [90.77.255.23]) (Authenticated sender: pneira@us.es) by entrada.int (Postfix) with ESMTPA id C399C42EF9E1; Tue, 11 Feb 2020 21:23:16 +0100 (CET) X-SMTPAUTHUS: auth mail.us.es From: Pablo Neira Ayuso To: netfilter-devel@vger.kernel.org Cc: fasnacht@protonmail.ch Subject: [PATCH nft 2/4] scanner: add indesc_file_alloc() helper function Date: Tue, 11 Feb 2020 21:23:06 +0100 Message-Id: <20200211202308.90575-3-pablo@netfilter.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200211202308.90575-1-pablo@netfilter.org> References: <20200211202308.90575-1-pablo@netfilter.org> X-Virus-Scanned: ClamAV using ClamSMTP Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org New helper function to allocate the file input_descriptor. Signed-off-by: Pablo Neira Ayuso --- src/scanner.l | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/scanner.l b/src/scanner.l index fe70df5c18ec..56f6e9956791 100644 --- a/src/scanner.l +++ b/src/scanner.l @@ -665,6 +665,22 @@ addrstring ({macaddr}|{ip4addr}|{ip6addr}) %% +static struct input_descriptor * +indesc_file_alloc(FILE *f, const char *filename, const struct location *loc) +{ + struct input_descriptor *indesc; + + indesc = xzalloc(sizeof(struct input_descriptor)); + if (loc != NULL) + indesc->location = *loc; + indesc->type = INDESC_FILE; + indesc->name = xstrdup(filename); + indesc->f = f; + init_pos(indesc); + + return indesc; +} + static void scanner_push_indesc(struct parser_state *state, struct input_descriptor *indesc) { @@ -702,15 +718,7 @@ static void scanner_push_file(struct nft_ctx *nft, void *scanner, b = yy_create_buffer(f, YY_BUF_SIZE, scanner); yypush_buffer_state(b, scanner); - indesc = xzalloc(sizeof(struct input_descriptor)); - - if (loc != NULL) - indesc->location = *loc; - indesc->type = INDESC_FILE; - indesc->name = xstrdup(filename); - indesc->f = f; - init_pos(indesc); - + indesc = indesc_file_alloc(f, filename, loc); scanner_push_indesc(state, indesc); } -- 2.11.0