diff options
author | Kevin McCarthy <kevin@8t8.us> | 2021-07-12 19:40:08 -0700 |
---|---|---|
committer | Kevin McCarthy <kevin@8t8.us> | 2021-07-17 15:14:59 -0700 |
commit | 6ecdb0917b6440f7eb115cc5ae598f23f17c7263 (patch) | |
tree | a2353801f61f8a711ffe4c929f17da00d44a80d1 /buffy.c | |
parent | 9b0a26310b5165c529e3c39f7ad4111103c06f65 (diff) |
Use memcpy in fseek_last_message() instead of strncpy.
We are copying raw bytes and don't care about embedded nuls, so
eliminate a compiler warning by using memcpy. BUFSIZ is guaranteed to
be at least 256.
Adjust the weird BUFSIZ + 9 size, which was added by an old commit
86f376dc that appears to have been a dead end. Also remove the no
longer relevant comment next to the strncpy.
Although it may be "safer" to use strlen() for the mutt_strncmp()
parameter, the code is performing this comparison over and over. We
already hardcode 7 in the buffer size and memcpy. So, make this loop
faster by hardcoding it here too.
Diffstat (limited to 'buffy.c')
-rw-r--r-- | buffy.c | 6 |
1 files changed, 3 insertions, 3 deletions
@@ -65,7 +65,7 @@ static BUFFY* buffy_get (const char *path); static int fseek_last_message (FILE * f) { LOFF_T pos; - char buffer[BUFSIZ + 9]; /* 7 for "\n\nFrom " */ + char buffer[BUFSIZ + 7]; /* 7 for "\n\nFrom " */ int bytes_read; int i; /* Index into `buffer' for scanning. */ @@ -83,13 +83,13 @@ static int fseek_last_message (FILE * f) while ((pos -= bytes_read) >= 0) { /* we save in the buffer at the end the first 7 chars from the last read */ - strncpy (buffer + BUFSIZ, buffer, 5+2); /* 2 == 2 * mutt_strlen(CRLF) */ + memcpy (buffer + BUFSIZ, buffer, 7); fseeko (f, pos, SEEK_SET); bytes_read = fread (buffer, sizeof (char), bytes_read, f); if (bytes_read == -1) return -1; for (i = bytes_read; --i >= 0;) - if (!mutt_strncmp (buffer + i, "\n\nFrom ", mutt_strlen ("\n\nFrom "))) + if (!mutt_strncmp (buffer + i, "\n\nFrom ", 7)) { /* found it - go to the beginning of the From */ fseeko (f, pos + i + 2, SEEK_SET); return 0; |