[PATCH v5 2/5] config: drop cf validity check in get_next_char()
- From
Heiko Voigt <hvoigt@hvoigt.net>
- Date
- Jul 11, 2013, 22:43 UTC
- Message-ID
- <20130711224302.GC26477@book-mint>
- In-Reply-To
- <20130711223614.GA26477@book-mint>
The global variable cf is set with an initialized value in all codepaths before calling this function.
The complete call graph looks like this:
git_config_from_file
-> do_config_from
-> git_parse_file
-> get_next_char
-> get_value
-> get_next_char
-> parse_value
-> get_next_char
-> get_base_var
-> get_next_char
-> get_extended_base_var
-> get_next_charThe variable is initialized in do_config_from.
Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net> --- config.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/config.c b/config.c index c165c85..1ec73ad 100644 --- a/config.c +++ b/config.c @@ -169,26 +169,23 @@ int git_config_from_parameters(config_fn_t fn, void *data) static int get_next_char(void) { int c; - FILE *f; + FILE *f = cf->f; - c = '\n'; - if (cf && ((f = cf->f) != NULL)) { + c = fgetc(f); + if (c == '\r') { + /* DOS like systems */ c = fgetc(f); - if (c == '\r') { - /* DOS like systems */ - c = fgetc(f); - if (c != '\n') { - ungetc(c, f); - c = '\r'; - } - } - if (c == '\n') - cf->linenr++; - if (c == EOF) { - cf->eof = 1; - c = '\n'; + if (c != '\n') { + ungetc(c, f); + c = '\r'; } } + if (c == '\n') + cf->linenr++; + if (c == EOF) { + cf->eof = 1; + c = '\n'; + } return c; }
-- 1.8.3.2.773.gcfaae5b