From: Ralph Corderoy Date: Sun, 30 Oct 2016 21:06:06 +0000 (+0000) Subject: fgets() reserves space for the NUL itself. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/939dea68806ab22c29755091b16236b48876442f?hp=128a282998fc767e226e6ff49969a2f3f4c31617 fgets() reserves space for the NUL itself. No need to knock one off the buffer size when calling it as that suggests something special is going on. --- diff --git a/sbr/ruserpass.c b/sbr/ruserpass.c index 43784d52..1d946fa2 100644 --- a/sbr/ruserpass.c +++ b/sbr/ruserpass.c @@ -147,7 +147,7 @@ ruserpass(const char *host, char **aname, char **apass, int flags) } printf("Name (%s:%s): ", host, myname); - if (fgets(tmp, sizeof(tmp) - 1, stdin) == NULL) { + if (fgets(tmp, sizeof tmp, stdin) == NULL) { advise ("tmp", "fgets"); } TrimSuffixC(tmp, '\n'); diff --git a/uip/mhstoresbr.c b/uip/mhstoresbr.c index cab9cee7..a2bc919e 100644 --- a/uip/mhstoresbr.c +++ b/uip/mhstoresbr.c @@ -835,7 +835,7 @@ losing: } } - while (fgets (buffer, sizeof(buffer) - 1, ct->c_fp)) { + while (fgets (buffer, sizeof buffer, ct->c_fp)) { if ((pos += strlen (buffer)) > last) { int diff; diff --git a/uip/post.c b/uip/post.c index bf1c042d..9940fa71 100644 --- a/uip/post.c +++ b/uip/post.c @@ -1527,7 +1527,7 @@ find_prefix (void) if ((in = fopen (tmpfil, "r")) == NULL) adios (tmpfil, "unable to re-open"); - while (fgets (buffer, sizeof(buffer) - 1, in)) + while (fgets (buffer, sizeof buffer, in)) if (buffer[0] == '-' && buffer[1] == '-') { char *cp; diff --git a/uip/sendsbr.c b/uip/sendsbr.c index 497c868b..33dd3451 100644 --- a/uip/sendsbr.c +++ b/uip/sendsbr.c @@ -286,7 +286,7 @@ splitmsg (char **vec, int vecp, char *program, char *drft, nparts = 1; pos = start; - while (fgets (buffer, sizeof(buffer) - 1, in)) { + while (fgets (buffer, sizeof buffer, in)) { long len; if ((pos += (len = strlen (buffer))) > CPERMSG) { @@ -356,7 +356,7 @@ splitmsg (char **vec, int vecp, char *program, char *drft, for (;;) { long len; - if (!fgets (buffer, sizeof(buffer) - 1, in)) { + if (!fgets (buffer, sizeof buffer, in)) { if (partno == nparts) break; adios (NULL, "premature eof");