diff options
| author | Paul Eggert | 2012-07-10 14:48:34 -0700 |
|---|---|---|
| committer | Paul Eggert | 2012-07-10 14:48:34 -0700 |
| commit | e99a530f8cdca3ccd9e739cd092ed9865d12fe89 (patch) | |
| tree | c2bef9f80ff9910be17757a83f61caed02146d0a /lib-src/movemail.c | |
| parent | c59592b32f5b5808c12720bfd37ea73b473fa1db (diff) | |
| download | emacs-e99a530f8cdca3ccd9e739cd092ed9865d12fe89.tar.gz emacs-e99a530f8cdca3ccd9e739cd092ed9865d12fe89.zip | |
Simplify by avoiding confusing use of strncpy etc.
Diffstat (limited to 'lib-src/movemail.c')
| -rw-r--r-- | lib-src/movemail.c | 45 |
1 files changed, 13 insertions, 32 deletions
diff --git a/lib-src/movemail.c b/lib-src/movemail.c index 3d994ec5a5e..b9a1be8a7f1 100644 --- a/lib-src/movemail.c +++ b/lib-src/movemail.c | |||
| @@ -141,8 +141,9 @@ static _Noreturn void fatal (const char *s1, const char *s2, const char *s3); | |||
| 141 | static void error (const char *s1, const char *s2, const char *s3); | 141 | static void error (const char *s1, const char *s2, const char *s3); |
| 142 | static _Noreturn void pfatal_with_name (char *name); | 142 | static _Noreturn void pfatal_with_name (char *name); |
| 143 | static _Noreturn void pfatal_and_delete (char *name); | 143 | static _Noreturn void pfatal_and_delete (char *name); |
| 144 | static char *concat (const char *s1, const char *s2, const char *s3); | 144 | #ifdef MAIL_USE_MAILLOCK |
| 145 | static long *xmalloc (unsigned int size); | 145 | static void *xmalloc (size_t size); |
| 146 | #endif | ||
| 146 | #ifdef MAIL_USE_POP | 147 | #ifdef MAIL_USE_POP |
| 147 | static int popmail (char *mailbox, char *outfile, int preserve, char *password, int reverse_order); | 148 | static int popmail (char *mailbox, char *outfile, int preserve, char *password, int reverse_order); |
| 148 | static int pop_retr (popserver server, int msgno, FILE *arg); | 149 | static int pop_retr (popserver server, int msgno, FILE *arg); |
| @@ -301,7 +302,7 @@ main (int argc, char **argv) | |||
| 301 | inname_dirlen && !IS_DIRECTORY_SEP (inname[inname_dirlen - 1]); | 302 | inname_dirlen && !IS_DIRECTORY_SEP (inname[inname_dirlen - 1]); |
| 302 | inname_dirlen--) | 303 | inname_dirlen--) |
| 303 | continue; | 304 | continue; |
| 304 | tempname = (char *) xmalloc (inname_dirlen + sizeof "EXXXXXX"); | 305 | tempname = xmalloc (inname_dirlen + sizeof "EXXXXXX"); |
| 305 | 306 | ||
| 306 | while (1) | 307 | while (1) |
| 307 | { | 308 | { |
| @@ -583,8 +584,8 @@ mail_spool_name (char *inname) | |||
| 583 | if (stat (MAILDIR, &stat1) < 0) | 584 | if (stat (MAILDIR, &stat1) < 0) |
| 584 | return NULL; | 585 | return NULL; |
| 585 | 586 | ||
| 586 | indir = (char *) xmalloc (fname - inname + 1); | 587 | indir = xmalloc (fname - inname + 1); |
| 587 | strncpy (indir, inname, fname - inname); | 588 | memcpy (indir, inname, fname - inname); |
| 588 | indir[fname-inname] = '\0'; | 589 | indir[fname-inname] = '\0'; |
| 589 | 590 | ||
| 590 | 591 | ||
| @@ -644,32 +645,18 @@ pfatal_and_delete (char *name) | |||
| 644 | fatal ("%s for %s", s, name); | 645 | fatal ("%s for %s", s, name); |
| 645 | } | 646 | } |
| 646 | 647 | ||
| 647 | /* Return a newly-allocated string whose contents concatenate those of s1, s2, s3. */ | 648 | #ifdef MAIL_USE_MAILLOCK |
| 648 | |||
| 649 | static char * | ||
| 650 | concat (const char *s1, const char *s2, const char *s3) | ||
| 651 | { | ||
| 652 | size_t len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3); | ||
| 653 | char *result = (char *) xmalloc (len1 + len2 + len3 + 1); | ||
| 654 | |||
| 655 | strcpy (result, s1); | ||
| 656 | strcpy (result + len1, s2); | ||
| 657 | strcpy (result + len1 + len2, s3); | ||
| 658 | *(result + len1 + len2 + len3) = 0; | ||
| 659 | |||
| 660 | return result; | ||
| 661 | } | ||
| 662 | |||
| 663 | /* Like malloc but get fatal error if memory is exhausted. */ | 649 | /* Like malloc but get fatal error if memory is exhausted. */ |
| 664 | 650 | ||
| 665 | static long * | 651 | static void * |
| 666 | xmalloc (unsigned int size) | 652 | xmalloc (size_t size) |
| 667 | { | 653 | { |
| 668 | long *result = (long *) malloc (size); | 654 | void *result = malloc (size); |
| 669 | if (!result) | 655 | if (!result) |
| 670 | fatal ("virtual memory exhausted", 0, 0); | 656 | fatal ("virtual memory exhausted", 0, 0); |
| 671 | return result; | 657 | return result; |
| 672 | } | 658 | } |
| 659 | #endif | ||
| 673 | 660 | ||
| 674 | /* This is the guts of the interface to the Post Office Protocol. */ | 661 | /* This is the guts of the interface to the Post Office Protocol. */ |
| 675 | 662 | ||
| @@ -851,10 +838,7 @@ pop_retr (popserver server, int msgno, FILE *arg) | |||
| 851 | 838 | ||
| 852 | if (pop_retrieve_first (server, msgno, &line)) | 839 | if (pop_retrieve_first (server, msgno, &line)) |
| 853 | { | 840 | { |
| 854 | char *msg = concat ("Error from POP server: ", pop_error, ""); | 841 | snprintf (Errmsg, sizeof Errmsg, "Error from POP server: %s", pop_error); |
| 855 | strncpy (Errmsg, msg, sizeof (Errmsg)); | ||
| 856 | Errmsg[sizeof (Errmsg)-1] = '\0'; | ||
| 857 | free (msg); | ||
| 858 | return (NOTOK); | 842 | return (NOTOK); |
| 859 | } | 843 | } |
| 860 | 844 | ||
| @@ -873,10 +857,7 @@ pop_retr (popserver server, int msgno, FILE *arg) | |||
| 873 | 857 | ||
| 874 | if (ret) | 858 | if (ret) |
| 875 | { | 859 | { |
| 876 | char *msg = concat ("Error from POP server: ", pop_error, ""); | 860 | snprintf (Errmsg, sizeof Errmsg, "Error from POP server: %s", pop_error); |
| 877 | strncpy (Errmsg, msg, sizeof (Errmsg)); | ||
| 878 | Errmsg[sizeof (Errmsg)-1] = '\0'; | ||
| 879 | free (msg); | ||
| 880 | return (NOTOK); | 861 | return (NOTOK); |
| 881 | } | 862 | } |
| 882 | 863 | ||