mailinfo: use strcmp() for string comparison
authorRené Scharfe <l.s.r@web.de>
Sun, 1 Jun 2014 09:00:40 +0000 (11:00 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 2 Jun 2014 20:30:18 +0000 (13:30 -0700)
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>
builtin/mailinfo.c
index 24a772d8e1b7355a58088d784fdc18cd54302b7d..6b44156264d246e363dd187666f142c7658c40b0 100644 (file)
@@ -334,7 +334,7 @@ static int check_header(const struct strbuf *line,
        }
        if (!prefixcmp(line->buf, "[PATCH]") && isspace(line->buf[7])) {
                for (i = 0; header[i]; i++) {
-                       if (!memcmp("Subject", header[i], 7)) {
+                       if (!strcmp("Subject", header[i])) {
                                handle_header(&hdr_data[i], line);
                                ret = 1;
                                goto check_header_out;
@@ -929,13 +929,13 @@ static void handle_info(void)
                else
                        continue;
 
-               if (!memcmp(header[i], "Subject", 7)) {
+               if (!strcmp(header[i], "Subject")) {
                        if (!keep_subject) {
                                cleanup_subject(hdr);
                                cleanup_space(hdr);
                        }
                        output_header_lines(fout, "Subject", hdr);
-               } else if (!memcmp(header[i], "From", 4)) {
+               } else if (!strcmp(header[i], "From")) {
                        cleanup_space(hdr);
                        handle_from(hdr);
                        fprintf(fout, "Author: %s\n", name.buf);