]> diplodocus.org Git - nmh/commitdiff
Don't call strlen() twice; save result.
authorRalph Corderoy <ralph@inputplus.co.uk>
Mon, 17 Oct 2016 00:36:35 +0000 (01:36 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Mon, 17 Oct 2016 00:36:35 +0000 (01:36 +0100)
The second instance was attempting to write strlen(mmdlm2) bytes
and checking the return value against strlen(mmdlm1).  I assumed
that was an error without digging.

uip/inc.c

index 8a71eb2..1e9f3c6 100644 (file)
--- a/uip/inc.c
+++ b/uip/inc.c
@@ -634,12 +634,14 @@ go_to_it:
 
            msgnum++;
            if (packfile) {
 
            msgnum++;
            if (packfile) {
+                size_t len;
+
                fseek (pf, 0L, SEEK_CUR);
                pos = ftell (pf);
                size = 0;
                fseek (pf, 0L, SEEK_CUR);
                pos = ftell (pf);
                size = 0;
-               if (fwrite (mmdlm1, 1, strlen (mmdlm1), pf) < strlen (mmdlm1)) {
+                len = strlen(mmdlm1);
+               if (fwrite(mmdlm1, 1, len, pf) < len)
                    advise (mmdlm1, "fwrite");
                    advise (mmdlm1, "fwrite");
-               }
                start = ftell (pf);
 
                if (pop_retr (i, pop_pack) == NOTOK)
                start = ftell (pf);
 
                if (pop_retr (i, pop_pack) == NOTOK)
@@ -693,10 +695,12 @@ go_to_it:
            charstring_free (scanl);
 
            if (packfile) {
            charstring_free (scanl);
 
            if (packfile) {
+                size_t len;
+
                fseek (pf, stop, SEEK_SET);
                fseek (pf, stop, SEEK_SET);
-               if (fwrite (mmdlm2, 1, strlen (mmdlm2), pf) < strlen (mmdlm1)) {
+                len = strlen(mmdlm2);
+               if (fwrite(mmdlm2, 1, len, pf) < len)
                    advise (mmdlm2, "fwrite");
                    advise (mmdlm2, "fwrite");
-               }
                if (fflush (pf) || ferror (pf)) {
                    int e = errno;
                    pop_quit ();
                if (fflush (pf) || ferror (pf)) {
                    int e = errno;
                    pop_quit ();