mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: SF Markus Elfring <elfring@users.sourceforge.net>
To: kernel-janitors@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH 2/4] ASN.1: Improve exiting from parse_type()
Date: Fri, 10 Nov 2017 13:48:10 +0100	[thread overview]
Message-ID: <6fd7f347-cdbb-9a0e-9817-8a35b262d8a6@users.sourceforge.net> (raw)
In-Reply-To: <960a8501-03b0-95d9-c2bf-4633e48e73a6@users.sourceforge.net>

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 10 Nov 2017 11:21:13 +0100

* Add a jump target so that a call of the function "exit" is stored
  only once at the end of this function.

* Replace nine calls by goto statements.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 scripts/asn1_compiler.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/scripts/asn1_compiler.c b/scripts/asn1_compiler.c
index e37e5ef3fabb..0eea270fcaef 100644
--- a/scripts/asn1_compiler.c
+++ b/scripts/asn1_compiler.c
@@ -896,7 +896,7 @@ static struct element *parse_type(struct token **_cursor, struct token *end,
 		default:
 			fprintf(stderr, "%s:%d: Unrecognised tag class token '%s'\n",
 				filename, cursor->line, cursor->content);
-			exit(1);
+			goto exit;
 		}
 
 		if (cursor >= end)
@@ -904,7 +904,7 @@ static struct element *parse_type(struct token **_cursor, struct token *end,
 		if (cursor->token_type != TOKEN_NUMBER) {
 			fprintf(stderr, "%s:%d: Missing tag number '%s'\n",
 				filename, cursor->line, cursor->content);
-			exit(1);
+			goto exit;
 		}
 
 		element->tag &= ~0x1f;
@@ -919,7 +919,7 @@ static struct element *parse_type(struct token **_cursor, struct token *end,
 		if (cursor->token_type != TOKEN_CLOSE_SQUARE) {
 			fprintf(stderr, "%s:%d: Missing closing square bracket '%s'\n",
 				filename, cursor->line, cursor->content);
-			exit(1);
+			goto exit;
 		}
 		cursor++;
 		if (cursor >= end)
@@ -1020,7 +1020,7 @@ static struct element *parse_type(struct token **_cursor, struct token *end,
 		if (!ref) {
 			fprintf(stderr, "%s:%d: Type '%s' undefined\n",
 				filename, cursor->line, cursor->content);
-			exit(1);
+			goto exit;
 		}
 		cursor->type = *ref;
 		(*ref)->ref_count++;
@@ -1070,7 +1070,7 @@ static struct element *parse_type(struct token **_cursor, struct token *end,
 	default:
 		fprintf(stderr, "%s:%d: Token '%s' does not introduce a type\n",
 			filename, cursor->line, cursor->content);
-		exit(1);
+		goto exit;
 	}
 
 	/* Handle elements that are optional */
@@ -1088,13 +1088,13 @@ static struct element *parse_type(struct token **_cursor, struct token *end,
 		if (cursor->token_type != TOKEN_ELEMENT_NAME) {
 			fprintf(stderr, "%s:%d: Token '%s' is not an action function name\n",
 				filename, cursor->line, cursor->content);
-			exit(1);
+			goto exit;
 		}
 
 		action = malloc(sizeof(struct action));
 		if (!action) {
 			perror(NULL);
-			exit(1);
+			goto exit;
 		}
 		action->index = 0;
 		action->name = cursor->content;
@@ -1129,7 +1129,7 @@ static struct element *parse_type(struct token **_cursor, struct token *end,
 		if (cursor->token_type != TOKEN_CLOSE_ACTION) {
 			fprintf(stderr, "%s:%d: Missing close action, got '%s'\n",
 				filename, cursor->line, cursor->content);
-			exit(1);
+			goto exit;
 		}
 		cursor++;
 	}
@@ -1140,10 +1140,11 @@ static struct element *parse_type(struct token **_cursor, struct token *end,
 parse_error:
 	fprintf(stderr, "%s:%d: Unexpected token '%s'\n",
 		filename, cursor->line, cursor->content);
-	exit(1);
+	goto exit;
 
 overrun_error:
 	fprintf(stderr, "%s: Unexpectedly hit EOF\n", filename);
+exit:
 	exit(1);
 }
 
-- 
2.15.0

  parent reply	other threads:[~2017-11-10 12:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-10 12:45 [PATCH 0/4] ASN.1: Fine-tuning for three function implementations SF Markus Elfring
2017-11-10 12:46 ` [PATCH 1/4] ASN.1: Adjust two function calls together with a variable assignment SF Markus Elfring
2017-11-10 12:48 ` SF Markus Elfring [this message]
2017-11-10 12:49 ` [PATCH 3/4] ASN.1: Improve exiting from build_type_list() SF Markus Elfring
2017-11-10 12:50 ` [PATCH 4/4] ASN.1: Use common error handling code in main() SF Markus Elfring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6fd7f347-cdbb-9a0e-9817-8a35b262d8a6@users.sourceforge.net \
    --to=elfring@users.sourceforge.net \
    --cc=akpm@linux-foundation.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome