X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=config.c;h=18d305c890d3f4ba00962cfa4033ff9ed68cf95b;hb=d5c527448db30be55553e0b125015e8d444f8dbc;hp=53f04a076a7275965090edd4ca2a34652c4f5679;hpb=372c767610c4e4d7f4832d037ac51a62a59875a3;p=git.git diff --git a/config.c b/config.c index 53f04a076..18d305c89 100644 --- a/config.c +++ b/config.c @@ -205,8 +205,27 @@ static int git_parse_file(config_fn_t fn, void *data) int baselen = 0; static char var[MAXNAME]; + /* U+FEFF Byte Order Mark in UTF8 */ + static const unsigned char *utf8_bom = (unsigned char *) "\xef\xbb\xbf"; + const unsigned char *bomptr = utf8_bom; + for (;;) { int c = get_next_char(); + if (bomptr && *bomptr) { + /* We are at the file beginning; skip UTF8-encoded BOM + * if present. Sane editors won't put this in on their + * own, but e.g. Windows Notepad will do it happily. */ + if ((unsigned char) c == *bomptr) { + bomptr++; + continue; + } else { + /* Do not tolerate partial BOM. */ + if (bomptr != utf8_bom) + break; + /* No BOM at file beginning. Cool. */ + bomptr = NULL; + } + } if (c == '\n') { if (config_file_eof) return 0; @@ -255,7 +274,7 @@ static int parse_unit_factor(const char *end, unsigned long *val) return 0; } -int git_parse_long(const char *value, long *ret) +static int git_parse_long(const char *value, long *ret) { if (value && *value) { char *end; @@ -291,7 +310,7 @@ static void die_bad_config(const char *name) int git_config_int(const char *name, const char *value) { - long ret; + long ret = 0; if (!git_parse_long(value, &ret)) die_bad_config(name); return ret;