mailinfo: use strcmp() for string comparison

The array header is defined as: static const char *header[MAX_HDR_PARSED] = { "From","Subject","Date", }; When looking for the index of a specfic string in that array, simply use strcmp() instead of memcmp(). This avoids running over the end of the string (e.g. with memcmp("Subject", "From", 7)) and gets rid of magic string length constants. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Jun 1, 2014 at 11:00 UTC b1a013dd6a79826675138cf9bdfaf18fafa786ba
1 file changed +3 -3
builtin/mailinfo.c
+3 -3
@@ -334,7 +334,7 @@ static int check_header(const struct strbuf *line,
334 }
335 if (!prefixcmp(line->buf, "[PATCH]") && isspace(line->buf[7])) {
336 for (i = 0; header[i]; i++) {
337 - if (!memcmp("Subject", header[i], 7)) {
337 + if (!strcmp("Subject", header[i])) {
338 handle_header(&hdr_data[i], line);
339 ret = 1;
340 goto check_header_out;
@@ -929,13 +929,13 @@ static void handle_info(void)
929 else
930 continue;
931
932 - if (!memcmp(header[i], "Subject", 7)) {
932 + if (!strcmp(header[i], "Subject")) {
933 if (!keep_subject) {
934 cleanup_subject(hdr);
935 cleanup_space(hdr);
936 }
937 output_header_lines(fout, "Subject", hdr);
938 - } else if (!memcmp(header[i], "From", 4)) {
938 + } else if (!strcmp(header[i], "From")) {
939 cleanup_space(hdr);
940 handle_from(hdr);
941 fprintf(fout, "Author: %s\n", name.buf);