fsck: make fsck_ident() warn-friendly
When fsck_ident() identifies a problem with the ident, it should still advance the pointer to the next line so that fsck can continue in the case of a mere warning. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Jun 22, 2015 at 17:26 UTC
e6826e335addb557dc80eebe46031f896ac4424c
1 file changed
+27
-22
fsck.c
+27
-22
@@ -482,40 +482,45 @@ static int require_end_of_header(const void *data, unsigned long size,
482
483
static int fsck_ident(const char **ident, struct object *obj, struct fsck_options *options)
484
{
485
+ const char *p = *ident;
486
char *end;
487
487
- if (**ident == '<')
488
+ *ident = strchrnul(*ident, '\n');
489
+ if (**ident == '\n')
490
+ (*ident)++;
491
+
492
+ if (*p == '<')
493
return report(options, obj, FSCK_MSG_MISSING_NAME_BEFORE_EMAIL, "invalid author/committer line - missing space before email");
489
- *ident += strcspn(*ident, "<>\n");
490
- if (**ident == '>')
494
+ p += strcspn(p, "<>\n");
495
+ if (*p == '>')
496
return report(options, obj, FSCK_MSG_BAD_NAME, "invalid author/committer line - bad name");
492
- if (**ident != '<')
497
+ if (*p != '<')
498
return report(options, obj, FSCK_MSG_MISSING_EMAIL, "invalid author/committer line - missing email");
494
- if ((*ident)[-1] != ' ')
499
+ if (p[-1] != ' ')
500
return report(options, obj, FSCK_MSG_MISSING_SPACE_BEFORE_EMAIL, "invalid author/committer line - missing space before email");
496
- (*ident)++;
497
- *ident += strcspn(*ident, "<>\n");
498
- if (**ident != '>')
501
+ p++;
502
+ p += strcspn(p, "<>\n");
503
+ if (*p != '>')
504
return report(options, obj, FSCK_MSG_BAD_EMAIL, "invalid author/committer line - bad email");
500
- (*ident)++;
501
- if (**ident != ' ')
505
+ p++;
506
+ if (*p != ' ')
507
return report(options, obj, FSCK_MSG_MISSING_SPACE_BEFORE_DATE, "invalid author/committer line - missing space before date");
503
- (*ident)++;
504
- if (**ident == '0' && (*ident)[1] != ' ')
508
+ p++;
509
+ if (*p == '0' && p[1] != ' ')
510
return report(options, obj, FSCK_MSG_ZERO_PADDED_DATE, "invalid author/committer line - zero-padded date");
506
- if (date_overflows(strtoul(*ident, &end, 10)))
511
+ if (date_overflows(strtoul(p, &end, 10)))
512
return report(options, obj, FSCK_MSG_BAD_DATE_OVERFLOW, "invalid author/committer line - date causes integer overflow");
508
- if (end == *ident || *end != ' ')
513
+ if ((end == p || *end != ' '))
514
return report(options, obj, FSCK_MSG_BAD_DATE, "invalid author/committer line - bad date");
510
- *ident = end + 1;
511
- if ((**ident != '+' && **ident != '-') ||
512
- !isdigit((*ident)[1]) ||
513
- !isdigit((*ident)[2]) ||
514
- !isdigit((*ident)[3]) ||
515
- !isdigit((*ident)[4]) ||
516
- ((*ident)[5] != '\n'))
515
+ p = end + 1;
516
+ if ((*p != '+' && *p != '-') ||
517
+ !isdigit(p[1]) ||
518
+ !isdigit(p[2]) ||
519
+ !isdigit(p[3]) ||
520
+ !isdigit(p[4]) ||
521
+ (p[5] != '\n'))
522
return report(options, obj, FSCK_MSG_BAD_TIMEZONE, "invalid author/committer line - bad time zone");
518
- (*ident) += 6;
523
+ p += 6;
524
return 0;
525
}
526