]> diplodocus.org Git - nmh/log
nmh
8 years agoinc/test-eom-align: Fix MMDF-mbox `B' size calculation.
Ralph Corderoy [Sun, 24 Sep 2017 13:10:18 +0000 (14:10 +0100)]
inc/test-eom-align: Fix MMDF-mbox `B' size calculation.

Also, have the email body end in what appears to be the MMDF magic
string for the first few bytes;  otherwise, the test mbox is just a
boring single email compared to the `A', From_, version.  Fixes
8699f1cc.

8 years agoinc/test-eom-align: Fix MMDF-mbox `A' size calculation.
Ralph Corderoy [Sun, 24 Sep 2017 12:49:32 +0000 (13:49 +0100)]
inc/test-eom-align: Fix MMDF-mbox `A' size calculation.

The `...LINESZ' variables are number of bytes, not number of lines, so
MMDF's is now 5 rather than 1.  And the MMDF magic string tops and tails
each email so needs to be subtracted twice, not once like From_'s.
Fixes 8699f1cc.

8 years agotest/common.sh.in: Only rm(1) if the cd(1) succeeds.
Ralph Corderoy [Sun, 24 Sep 2017 12:12:46 +0000 (13:12 +0100)]
test/common.sh.in: Only rm(1) if the cd(1) succeeds.

The rm specified the full path anyway, but if the cd fails for some odd
reason then it's best not to continue.

8 years agoannosbr.c: free(3) takes void pointer; don't cast non-const pointer.
Ralph Corderoy [Sun, 24 Sep 2017 11:56:26 +0000 (12:56 +0100)]
annosbr.c: free(3) takes void pointer; don't cast non-const pointer.

(const pointers are another whole can of worms, and their const
poisoning causes much noise for little benefit.)

8 years agovoid-pointer parameters don't need casting to char pointer.
Ralph Corderoy [Sun, 24 Sep 2017 11:31:35 +0000 (12:31 +0100)]
void-pointer parameters don't need casting to char pointer.

E.g. `memcmp((char *)digest...' doesn't need the cast if it's already a
pointer.

8 years agoReplace `sizeof (char)' with 1, then remove if a multiplier.
Ralph Corderoy [Sun, 24 Sep 2017 11:21:48 +0000 (12:21 +0100)]
Replace `sizeof (char)' with 1, then remove if a multiplier.

8 years agoDon't cast void pointer return value of malloc() et al.
Ralph Corderoy [Sun, 24 Sep 2017 11:20:26 +0000 (12:20 +0100)]
Don't cast void pointer return value of malloc() et al.

8 years agoStop failed m_mktemp2() that give directory reporting get_temp_dir().
Ralph Corderoy [Sat, 23 Sep 2017 21:27:46 +0000 (22:27 +0100)]
Stop failed m_mktemp2() that give directory reporting get_temp_dir().

The first parameter of m_mktemp2(), if not NULL, is a path and the
basename is used as the directory to hold the new temporary file, but
the error message on failing to create that used get_temp_dir() and
that's often somewhere else, e.g. `mhbuild /dev/null' attempts /dev/...
Don't attempt to state the failed path in the error message as at least
that's not misleading.  Perhaps the function needs some other indication
of success so it can pass back the attempted filename that failed.

8 years agomhbuild.c: Don't use set_done() to unlink temporary files.
Ralph Corderoy [Sat, 23 Sep 2017 17:16:26 +0000 (18:16 +0100)]
mhbuild.c: Don't use set_done() to unlink temporary files.

Because they're created with m_mktemp2(), the temporary files are
already in a list to be unlink(2)'d at exit(3), thanks to atexit(3), so
don't set_done() to attempt that twice.  Updates 6bc64765f.

8 years agomhshow/test-charset: Test iconv(1)'s result, not just its exit status.
Ralph Corderoy [Sat, 23 Sep 2017 13:29:38 +0000 (14:29 +0100)]
mhshow/test-charset: Test iconv(1)'s result, not just its exit status.

Problems with generating the input to iconv(1) were hidden as long as it
could be converted from EBCDIC-US to UTF-8 because only the exit status
was tested.  Check the output is as expected too.

8 years agomhshow/test-charset: printf(1)'s octal doesn't need a leading zero.
Ralph Corderoy [Sat, 23 Sep 2017 13:14:12 +0000 (14:14 +0100)]
mhshow/test-charset: printf(1)'s octal doesn't need a leading zero.

The `\0344' was being interpreted as `\034' and `4'.  This can still be
converted from EBCDIC-US to UTF-8 by iconv(1) so the test worked, but it
was misleading.  Remove the leading zero as printf's octal escape is
`\nnn' where nnn is one to three octal digits.  It's echo(1) that
insists on a leading zero.  Fixes 6fd1d18f.

8 years agoinc/test-eom-align: Use octal, not hex, in printf(1) format string.
Ralph Corderoy [Sat, 23 Sep 2017 10:43:12 +0000 (11:43 +0100)]
inc/test-eom-align: Use octal, not hex, in printf(1) format string.

POSIX's printf(1), and dash(1)'s, does not support hex.  Fixes 8699f1cc.

8 years agomhshow/test-charset: Use octal, not hex, in printf(1) format string.
Ralph Corderoy [Sat, 23 Sep 2017 10:40:39 +0000 (11:40 +0100)]
mhshow/test-charset: Use octal, not hex, in printf(1) format string.

POSIX's printf(1), and dash(1)'s, does not support hex.  Fixes 792d7e1e.

8 years agoAdded tests of MMDF mailbox format to test-eom-align.
David Levine [Fri, 22 Sep 2017 23:05:49 +0000 (19:05 -0400)]
Added tests of MMDF mailbox format to test-eom-align.

8 years agorunpty.c: Move child slave code into new run_command().
Ralph Corderoy [Fri, 22 Sep 2017 12:04:12 +0000 (13:04 +0100)]
runpty.c: Move child slave code into new run_command().

8 years agorunpty.c: Handle fork(2) failure first, rather than child.
Ralph Corderoy [Fri, 22 Sep 2017 11:49:47 +0000 (12:49 +0100)]
runpty.c: Handle fork(2) failure first, rather than child.

Gets the error handling out of the way so it can be forgotten.

8 years agorunpty.c: Factor duplicate code into new open_master_pty().
Ralph Corderoy [Fri, 22 Sep 2017 11:47:02 +0000 (12:47 +0100)]
runpty.c: Factor duplicate code into new open_master_pty().

Only called twice, but it shows the same actions are done both times.

8 years agorunpty.c: Replace fprintf()+exit() pairs with new die().
Ralph Corderoy [Fri, 22 Sep 2017 11:36:05 +0000 (12:36 +0100)]
runpty.c: Replace fprintf()+exit() pairs with new die().

8 years agoDetect function-pointer `done' being set twice in a row.
Ralph Corderoy [Thu, 21 Sep 2017 15:59:15 +0000 (16:59 +0100)]
Detect function-pointer `done' being set twice in a row.

Make `done' a function that uses a file-static function pointer, and add
set_done() to alter it.  That wants either the old or new value to be
exit(3).  If it's not, it still alters the stored pointer, to maintain
the existing behaviour, but emits a warning on stderr.  mhbuild(1)
triggers that warning, making this hunch worthwhile.

8 years agoman: Replace csh `%' prompt in examples with sh's `$'.
Ralph Corderoy [Thu, 21 Sep 2017 13:21:38 +0000 (14:21 +0100)]
man: Replace csh `%' prompt in examples with sh's `$'.

Youngsters these days probably wouldn't recognise csh.  None of the
commands needed changing due to syntax differences.

8 years agomh-draft.man: Use ASCII double-quote for itself in example output.
Ralph Corderoy [Thu, 21 Sep 2017 13:12:00 +0000 (14:12 +0100)]
mh-draft.man: Use ASCII double-quote for itself in example output.

Not the TeX doubling of backquote and single-quote.

8 years agoman: Add backslash before backquote so it appears as sh backtick.
Ralph Corderoy [Thu, 21 Sep 2017 13:05:05 +0000 (14:05 +0100)]
man: Add backslash before backquote so it appears as sh backtick.

8 years agoman: Fix backquote used in error for single quote.
Ralph Corderoy [Tue, 19 Sep 2017 22:16:36 +0000 (23:16 +0100)]
man: Fix backquote used in error for single quote.

A repeated bit of prose had the typo `foo` instead of `foo'.

8 years agomhlsbr.c: Delete file-static function pointer mhl_action.
Ralph Corderoy [Tue, 19 Sep 2017 10:43:30 +0000 (11:43 +0100)]
mhlsbr.c: Delete file-static function pointer mhl_action.

Never set, so always NULL due to BSS.  It used to be set by c808c5d5.

8 years agomhlsbr.c: Delete `jmp_buf mhlenv', never setjmp(3)'d.
Ralph Corderoy [Tue, 19 Sep 2017 10:38:52 +0000 (11:38 +0100)]
mhlsbr.c: Delete `jmp_buf mhlenv', never setjmp(3)'d.

Only ever conditionally longjmp(3)'d.  The setjmp() was removed by
c808c5d5.

8 years agoStrip parenthesis from `return (state = OK);' and similar.
Ralph Corderoy [Mon, 18 Sep 2017 23:00:08 +0000 (00:00 +0100)]
Strip parenthesis from `return (state = OK);' and similar.

There are sufficient cases without the parenthesis that various
compilers must be happy without.

8 years agopop_init(): After proxy's execve(2) failure, exit(1), not exit(10).
Ralph Corderoy [Mon, 18 Sep 2017 22:38:27 +0000 (23:38 +0100)]
pop_init(): After proxy's execve(2) failure, exit(1), not exit(10).

The value 10 seems undocumented, and I can't find anything that tests
for that specific value.

8 years agosendfiles: Always die with exit status of 1 rather than -1.
Ralph Corderoy [Mon, 18 Sep 2017 22:29:24 +0000 (23:29 +0100)]
sendfiles: Always die with exit status of 1 rather than -1.

The sh function die() took the exit status as an optional parameter,
with a default of -1, but this was never used so remove the option and
always use an exit status of 1.

8 years agoRemove preprocessor conditionals on `lint'.
Ralph Corderoy [Mon, 18 Sep 2017 14:28:26 +0000 (15:28 +0100)]
Remove preprocessor conditionals on `lint'.

Treat all tests for `lint' being defined as false.  Don't know when
anyone had a lint(1) that could be run on the source, but none of the
areas had been touched in git's history, and at least one would have
been a compile error had it been defined.

8 years agoReplace `_exit(-1)' with `_exit(1)'.
Ralph Corderoy [Mon, 18 Sep 2017 14:04:07 +0000 (15:04 +0100)]
Replace `_exit(-1)' with `_exit(1)'.

In line with other changes to limit a process's exit value to small
non-negative integers distinguishable with sh's `$?'.

8 years agowhom.c: Don't call rename(2) with source that's uninitialised.
Ralph Corderoy [Mon, 18 Sep 2017 11:43:28 +0000 (12:43 +0100)]
whom.c: Don't call rename(2) with source that's uninitialised.

The intent is that two rename(2)s take place: to move a file to a
backup and then return it.  The first test controlled the generation of
the destination in the char array `backup' and calling the first
rename().  The second test used that same array for the restoring
rename(), but used a different test and so could run when the first
rename hadn't, and with an uninitialised array for the source filename.

The initialisation of `backup' and the first rename needed both
environment variables `mhdist' and `mhaltmsg' to be non-empty, and the
former to have a non-zero atoi(3) value.  The second rename ignored
`mhaltmsg'.  Bug pre-dates git.

8 years agowhom.c: Re-work fork/exec logic to clarify interaction with distsw.
Ralph Corderoy [Mon, 18 Sep 2017 11:31:58 +0000 (12:31 +0100)]
whom.c: Re-work fork/exec logic to clarify interaction with distsw.

8 years agoIf fork(2) fails then die; don't fall through to execve(2).
Ralph Corderoy [Mon, 18 Sep 2017 11:12:58 +0000 (12:12 +0100)]
If fork(2) fails then die;  don't fall through to execve(2).

It's already been agreed that failure to fork() is so rare these days
that multiple attempts aren't required.  Nor should the code persevere
by calling execve() as if the fork had succeeded, else why bother to
fork?  Instead, die.

8 years agowhom.c: Don't increment atoi(3)'s return value as it's already true.
Ralph Corderoy [Mon, 18 Sep 2017 10:59:37 +0000 (11:59 +0100)]
whom.c: Don't increment atoi(3)'s return value as it's already true.

atoi(3) has returned non-zero and distsw holds that value.  Only the
truthness of distsw matters.  Don't increment distsw, as if to show it's
been set, because that would turn the true -1 to false 0.  Bug pre-dates
git.

8 years agowhom.c: Don't store atoi(getenv("mhdist")) when value only tested.
Ralph Corderoy [Mon, 18 Sep 2017 10:56:26 +0000 (11:56 +0100)]
whom.c: Don't store atoi(getenv("mhdist")) when value only tested.

It's the non-zero value of atoi(3) that's important in the if-condition;
the value is never used again.

8 years agomhlsbr.c: Don't strchr(3) non-string NUL-less buffer.
Ralph Corderoy [Sun, 17 Sep 2017 12:19:40 +0000 (13:19 +0100)]
mhlsbr.c: Don't strchr(3) non-string NUL-less buffer.

Up to 8 KiB was read into a buffer and then strchr() used to test for a
linefeed.  There was no guarantee the linefeed would be present, else
why test for it, nor that the buffer would contain a NUL to terminate
the search, either from the read bytes, or the bytes not trampled by
read().  Replace the two similar lumps of code with a new
linefeed_typed().  Bug pre-dates git.

8 years agomhlsbr.c: Don't read(2) from fileno(3) of stdout.
Ralph Corderoy [Sat, 16 Sep 2017 21:58:11 +0000 (22:58 +0100)]
mhlsbr.c: Don't read(2) from fileno(3) of stdout.

Remove the assumption that file descriptor 1 is readable.  It can be if
it, or where it was dup(2)'d from, was opened read/write, e.g. on
/dev/tty.  But it can easily be arranged with shell re-direction that it
isn't, and then the read(2) fails.  Pass 0, standard input's file
descriptor, instead.  Don't use fileno(stdin) as I can't think of a need
to support that being non-zero, but its use makes the reader think it
might.  Bug pre-dates git.

8 years agoInvert ternary condition to remove one negative.
Ralph Corderoy [Fri, 15 Sep 2017 21:58:59 +0000 (22:58 +0100)]
Invert ternary condition to remove one negative.

Replaces `i != NOTOK ? OK : NOTOK' with `i == NOTOK ? NOTOK : OK'.

8 years agomime_type.c: Fix regexp in comment that describes following code.
Ralph Corderoy [Fri, 15 Sep 2017 12:03:20 +0000 (13:03 +0100)]
mime_type.c: Fix regexp in comment that describes following code.

Fixes e35fb433.

8 years agoaddrsbr.c: Alter ismymbox() to return bool, not int.
Ralph Corderoy [Wed, 13 Sep 2017 22:31:25 +0000 (23:31 +0100)]
addrsbr.c: Alter ismymbox() to return bool, not int.

It was returning 0 or 1.

8 years agosmtp.c: Have function returning char pointer return NULL, not 0.
Ralph Corderoy [Wed, 13 Sep 2017 22:29:12 +0000 (23:29 +0100)]
smtp.c: Have function returning char pointer return NULL, not 0.

8 years agoext_hook(): Flip if-statement condition so then-block simply returns.
Ralph Corderoy [Wed, 13 Sep 2017 22:16:50 +0000 (23:16 +0100)]
ext_hook(): Flip if-statement condition so then-block simply returns.

No need for rest of function to be in an else-block.

8 years agonew.c: Order two return statements to match comment.
Ralph Corderoy [Wed, 13 Sep 2017 22:15:50 +0000 (23:15 +0100)]
new.c: Order two return statements to match comment.

No change in behaviour.

8 years agoEdit out a few more tautological `the foo(5) man page'.
Ralph Corderoy [Wed, 13 Sep 2017 22:08:00 +0000 (23:08 +0100)]
Edit out a few more tautological `the foo(5) man page'.

8 years agonmh_completion(): Simplify, removing local variable.
Ralph Corderoy [Wed, 13 Sep 2017 10:31:29 +0000 (11:31 +0100)]
nmh_completion(): Simplify, removing local variable.

8 years agoRemove casts of NULL to a data pointer.
Ralph Corderoy [Wed, 13 Sep 2017 10:09:42 +0000 (11:09 +0100)]
Remove casts of NULL to a data pointer.

With a function prototype in place stating a parameter is a foo pointer,
where foo is data, not a function, then `NULL' suffices so the cast to
foo pointer is redundant.  If the function parameter is retrieved with
va_arg(3) then the pointer passed must be the retrieved type, e.g.
concat()'s arguments are fetched as char pointer and so it should be
called as `concat("foo", (char *)0)'.  Using NULL is incorrect, though
NULL could be used instead of 0 but still needs casting.  However, the
source doesn't bother getting this right and just passes NULL in most
cases so make the few match.  Most of those changed were passing NULL
cast to a void pointer.

8 years agoRemove more outer wrapping parenthesis from return statements.
Ralph Corderoy [Tue, 12 Sep 2017 23:14:43 +0000 (00:14 +0100)]
Remove more outer wrapping parenthesis from return statements.

For example, `return(foo(a, b));' becomes `return foo(a, b);'.

8 years agodmktime(): Break assignments so `*=' and `+=' can be used.
Ralph Corderoy [Tue, 12 Sep 2017 14:49:30 +0000 (15:49 +0100)]
dmktime(): Break assignments so `*=' and `+=' can be used.

Add comments tracking the units of `result' from days to seconds.

8 years agoReplace `return (0)' and similar with `return 0'.
Ralph Corderoy [Tue, 12 Sep 2017 14:34:31 +0000 (15:34 +0100)]
Replace `return (0)' and similar with `return 0'.

Just outer parenthesis removed.

8 years agoHoick FENDNULL(key) out of the search loop.
Ralph Corderoy [Tue, 12 Sep 2017 14:02:41 +0000 (15:02 +0100)]
Hoick FENDNULL(key) out of the search loop.

`key' is a loop-invariant so can be tested for NULL once before the
loop.  In one case, this also avoid passing NULL to printf(3) for "%s",
and means getcpy()s can be replaced with mh_xstrdup()s.

8 years agomh_oauth_cred_fn()'s return value no longer needs duplicating.
Ralph Corderoy [Tue, 12 Sep 2017 13:55:16 +0000 (14:55 +0100)]
mh_oauth_cred_fn()'s return value no longer needs duplicating.

It now returns a fresh allocation so that can be used directly rather
than obtaining another copy.

8 years agomh_oauth_cred_fn(): Always freshly allocate result.
Ralph Corderoy [Tue, 12 Sep 2017 13:32:33 +0000 (14:32 +0100)]
mh_oauth_cred_fn(): Always freshly allocate result.

If a `credential-file' context was found, and started with a `/', then
the m_defs's n_field was returned, otherwise a newly allocated string.
The caller couldn't tell whether to free the result or not so memory was
leaked.  Alter it to always freshly allocate the result.  Fixes
803f25412.

8 years agoexmaildir(): Don't leak memory allocated by path().
Ralph Corderoy [Tue, 12 Sep 2017 12:26:22 +0000 (13:26 +0100)]
exmaildir(): Don't leak memory allocated by path().

Bug pre-dates git.

8 years agomime_type(): Don't leak memory allocated by get_file_info().
Ralph Corderoy [Tue, 12 Sep 2017 12:20:56 +0000 (13:20 +0100)]
mime_type(): Don't leak memory allocated by get_file_info().

Fixes b4f2851d4.

8 years agolock_file.c: close(2) file descriptor on failure, avoiding leak.
Ralph Corderoy [Tue, 12 Sep 2017 11:40:49 +0000 (12:40 +0100)]
lock_file.c: close(2) file descriptor on failure, avoiding leak.

Fixes d6e398f9c.

8 years agomhfixmsg.c: Fix memory leak of temporary filename if write fails.
Ralph Corderoy [Mon, 11 Sep 2017 23:07:50 +0000 (00:07 +0100)]
mhfixmsg.c: Fix memory leak of temporary filename if write fails.

8 years agomhfixmsg.c: Fix memory leaks of boundary string on early returns.
Ralph Corderoy [Mon, 11 Sep 2017 23:06:35 +0000 (00:06 +0100)]
mhfixmsg.c: Fix memory leaks of boundary string on early returns.

8 years agoDelete mh_xfree(), changing callers to call free(3) instead.
Ralph Corderoy [Mon, 11 Sep 2017 17:56:50 +0000 (18:56 +0100)]
Delete mh_xfree(), changing callers to call free(3) instead.

A free(3) that didn't handle NULL is now long past.

8 years agormf.c: free(3) return value from m_mailpath() calls.
Ralph Corderoy [Mon, 11 Sep 2017 17:37:38 +0000 (18:37 +0100)]
rmf.c: free(3) return value from m_mailpath() calls.

And add comment to m_mailpath() that its return value needs freeing.

8 years agopath.c: Add comments declaring return values must be free(3)'d.
Ralph Corderoy [Mon, 11 Sep 2017 17:28:10 +0000 (18:28 +0100)]
path.c: Add comments declaring return values must be free(3)'d.

Saves working it out afresh each visit.

8 years agopath.c: Remove path()'s test for expath() returning NULL.
Ralph Corderoy [Mon, 11 Sep 2017 17:25:20 +0000 (18:25 +0100)]
path.c: Remove path()'s test for expath() returning NULL.

All paths out of expath() have it calling mh_xstrdup().

8 years agopath.c: Re-format path() to make it more clear what's happening.
Ralph Corderoy [Mon, 11 Sep 2017 17:23:33 +0000 (18:23 +0100)]
path.c: Re-format path() to make it more clear what's happening.

8 years agoslocal.c: Alter trim() to return static array, not malloc(3).
Ralph Corderoy [Sun, 10 Sep 2017 17:12:38 +0000 (18:12 +0100)]
slocal.c: Alter trim() to return static array, not malloc(3).

The callers are immediately passing the return value to printf(3) for
"%s".  There's only one call per printf().  None of the callers are
bothering to free(3) the existing return value.  Return the address of
trim()'s char array, now static, instead.  Leave trim() returning NULL
when passed NULL, even though that gives NULL to print(3) for "%s".  It,
and slocal's other bugs, remain.

8 years agoRemove test for `\0' in `*s && isfoo(*s)' for ctype.h calls.
Ralph Corderoy [Sun, 10 Sep 2017 16:19:56 +0000 (17:19 +0100)]
Remove test for `\0' in `*s && isfoo(*s)' for ctype.h calls.

8 years agofind_cache(): Remove test that's always false.
Ralph Corderoy [Sun, 10 Sep 2017 14:11:18 +0000 (15:11 +0100)]
find_cache(): Remove test that's always false.

The if-statement's condition is a conjunctive that tests `!writing' and
then, only if that's true, calls find_cache_aux() and tests `writing' in
determining the first argument;  that must be false.  Bug pre-dates git
history.

8 years agoreadline(3) wrapper: Move free(3) of line to where it's reachable.
Ralph Corderoy [Sun, 10 Sep 2017 14:03:09 +0000 (15:03 +0100)]
readline(3) wrapper: Move free(3) of line to where it's reachable.

Every line returned by readline() has to be freed.  The call to free()
was unreachable because all paths heading towards it veered off,
resulting in a memory leak.  Move the free() to just after where the
line has been used for the last time.  Fixes 3a85e0bc9.

8 years agofmt_compile.c: Alter FINDCOMP(): the caller must supply the semicolon.
Ralph Corderoy [Sun, 10 Sep 2017 13:53:32 +0000 (14:53 +0100)]
fmt_compile.c: Alter FINDCOMP(): the caller must supply the semicolon.

The macro expands to a for-loop, including the semicolon body.  The
caller typically supplies their own semicolon.  This results in two on
one line that looks odd.  Alter the macro to have the for-loop inside a
do-while loop that doesn't have a semicolon, ensuring the caller must
supply it.

8 years agoargsplit(): Incorrect type used in sizeof calculation for array.
Ralph Corderoy [Sun, 10 Sep 2017 13:44:15 +0000 (14:44 +0100)]
argsplit(): Incorrect type used in sizeof calculation for array.

Switched to referring to the variable being assigned the resulting
memory rather than duplicating its type information.  Fixes 78211e93.

8 years agoget_file_info(): Flip logic throughout, reducing nesting.
Ralph Corderoy [Sun, 10 Sep 2017 13:22:29 +0000 (14:22 +0100)]
get_file_info(): Flip logic throughout, reducing nesting.

Now a series of small paragraphs, each of which might return on error.
Also, the Cygwin oddity described in the comment needs no special
handling given the recent bug fixes so it can be deleted.

8 years agoget_file_info(): Don't return filename from quote onwards on error.
Ralph Corderoy [Sun, 10 Sep 2017 12:38:18 +0000 (13:38 +0100)]
get_file_info(): Don't return filename from quote onwards on error.

If `file_name' contained a quote then `cp' points to it, and remains
pointing to it if any of concat(), popen(3), or fgets(3) fail to give
the expected result.  On returning, cp is not NULL and so strdup(cp) is
returned.  Also, if fgets() fails on Cygwin in the way the comment
describes then cp is wrongly free(3)'d.  (One of the problems with
generic variable names is their overloaded semantics cause faulty
re-use.)  Fixes b4f2851d and 0c50c669.

8 years agoget_file_info(): Don't dereference out of scope char array.
Ralph Corderoy [Sun, 10 Sep 2017 12:29:46 +0000 (13:29 +0100)]
get_file_info(): Don't dereference out of scope char array.

A pointer to `char buf[...]' is taken, the array being declared in a
block scope inside the function.  The pointer is passed to strdup(3) as
the function returned, but the array is by then out of scope.  Move the
array to the function's scope.  Fixes 0c50c669.

8 years agoReplace parallel MIME-preference arrays with struct array.
Ralph Corderoy [Sun, 10 Sep 2017 11:28:51 +0000 (12:28 +0100)]
Replace parallel MIME-preference arrays with struct array.

New array of struct has `type' and `subtype' members, replacing the old
preferred_types[] and preferred_subtypes[] arrays.

8 years agopidstatus(): Rewrite to print stopped and continued statuses too.
Ralph Corderoy [Sun, 10 Sep 2017 11:14:20 +0000 (12:14 +0100)]
pidstatus(): Rewrite to print stopped and continued statuses too.

Delete own versions of WTERMSIG and WCOREDUMP macros now we're assuming
POSIX.

8 years agopidstatus(): Delete commented-out code testing for exit(255).
Ralph Corderoy [Sun, 10 Sep 2017 10:35:20 +0000 (11:35 +0100)]
pidstatus(): Delete commented-out code testing for exit(255).

Pre-dating git, a test of wait(2)'s status having its top eight bits all
set was commented out an "I've no idea what this does" explanation.  The
top eight bits hold either exit(3)'s parameter or the signal that caused
the child to stop.  Either way, there are macros for pulling apart that
value and they're being used.  Perhaps they were broken on a much older
system.  Delete the comment, including its code.

8 years agoReplace printf("%s\n", foo) and similar with puts(foo).
Ralph Corderoy [Sun, 10 Sep 2017 10:21:42 +0000 (11:21 +0100)]
Replace printf("%s\n", foo) and similar with puts(foo).

8 years agodatetime.c: Flip if-conditions so returns move from else block.
Ralph Corderoy [Sat, 9 Sep 2017 22:27:00 +0000 (23:27 +0100)]
datetime.c: Flip if-conditions so returns move from else block.

Then there's no need for else-blocks after return.

8 years agoicalendar.l: Refer to base64.h relative to root of source.
Ralph Corderoy [Sat, 9 Sep 2017 21:56:45 +0000 (22:56 +0100)]
icalendar.l: Refer to base64.h relative to root of source.

Ken reported a missing-include-file problem when building so the product
ends up outside the source tree, e.g. running configure from elsewhere.
It must also depend on his environment, e.g. OS or compiler, because the
problem isn't reproducible with Arch Linux and gcc, and be specific to C
source built from other source files, e.g. lex(1).  However, given that
the existing sibling icalparse.h is referred to as sbr/..., duplicate
that so it builds for Ken too.

8 years agotest/getcanon.c: exit(3) with 0 or 1, not -1 or symbolic error code.
Ralph Corderoy [Sat, 9 Sep 2017 21:45:54 +0000 (22:45 +0100)]
test/getcanon.c: exit(3) with 0 or 1, not -1 or symbolic error code.

gethostname(3) returns -1 on failure and that was being returned from
main;  use 1 instead.  getaddrinfo(3) returns EAI_ADDRFAMILY et al on
failure, but here they're defined as small negative integers, unsuitable
for main()'s return value;  again, use 1 instead.  Along the way, flip
the logic so the end is nigh when possible, avoiding the cognitive
overhead of tracking state when continuing to read through the source.

8 years agotest/getfullname.c: Move return case first in if-else chain.
Ralph Corderoy [Sat, 9 Sep 2017 21:08:43 +0000 (22:08 +0100)]
test/getfullname.c: Move return case first in if-else chain.

8 years agoRefer to #include files from the root of nmh's source.
Ralph Corderoy [Sat, 9 Sep 2017 20:56:42 +0000 (21:56 +0100)]
Refer to #include files from the root of nmh's source.

One of the -I options given to the C compiler is the root of the nmh
source.  This means uip/foo.c's #include of the relative ../sbr/bar.h
can also be written more tidily as sbr/bar.h.

8 years agoicalparse.y: Remove else-block that returns by merging if-conditions.
Ralph Corderoy [Sat, 9 Sep 2017 20:30:39 +0000 (21:30 +0100)]
icalparse.y: Remove else-block that returns by merging if-conditions.

The code tested two values to see if they were present, and if they
were, and were equal, then it returned this node.  If either were
missing then this node was still returned because it matched the more
limited criteria that had already been tested.  So the test for
returning this node can more simply be if either value to compare is
missing, or they're (both present and) equal.

8 years agoseq_setprev.c: Flip if-condition so return moves from else block.
Ralph Corderoy [Sat, 9 Sep 2017 17:29:58 +0000 (18:29 +0100)]
seq_setprev.c: Flip if-condition so return moves from else block.

Then no need for else block after return.

8 years agofolder_pack.c: Flip if-condition so return moves from else block.
Ralph Corderoy [Sat, 9 Sep 2017 17:28:31 +0000 (18:28 +0100)]
folder_pack.c: Flip if-condition so return moves from else block.

Then no need for else block after return.

8 years agoseq_setunseen.c: Flip if-condition so return moves from else block.
Ralph Corderoy [Sat, 9 Sep 2017 17:27:42 +0000 (18:27 +0100)]
seq_setunseen.c: Flip if-condition so return moves from else block.

Then no need for else block after return.

8 years agomhstoresbr.c: Flip if-condition so return moves from else block.
Ralph Corderoy [Sat, 9 Sep 2017 17:26:45 +0000 (18:26 +0100)]
mhstoresbr.c: Flip if-condition so return moves from else block.

Then no need for else block after return.

8 years agoread_switch_multiword.c: Flip if-condition so return moves from else block.
Ralph Corderoy [Sat, 9 Sep 2017 17:20:09 +0000 (18:20 +0100)]
read_switch_multiword.c: Flip if-condition so return moves from else block.

Then no need for else block after return.

8 years agodatetime.c: Don't atoi("0") if zone is NULL.
Ralph Corderoy [Sat, 9 Sep 2017 11:26:40 +0000 (12:26 +0100)]
datetime.c: Don't atoi("0") if zone is NULL.

8 years agodatetime.c: Fix parse-failure's error-message's daylight indication.
Ralph Corderoy [Sat, 9 Sep 2017 11:05:22 +0000 (12:05 +0100)]
datetime.c: Fix parse-failure's error-message's daylight indication.

`in_standard' was being used to decide between `standard' and `daylight'
in the error message, but it would always be false by that point.
`in_daylight' is what's passed to the parsing function so use that to
determine the string instead.  Bug present since the initial
implementation.

8 years agodatetime.c: Replace some int with bool.
Ralph Corderoy [Sat, 9 Sep 2017 10:57:15 +0000 (11:57 +0100)]
datetime.c: Replace some int with bool.

8 years agoOnly call fork(2) once, not up to five times on failure.
Ralph Corderoy [Sat, 9 Sep 2017 10:32:01 +0000 (11:32 +0100)]
Only call fork(2) once, not up to five times on failure.

The existing loop that slept five seconds between each attempt was
copy-pasted widely.  Those days are gone.  Just call it once.

8 years agocontent_error(): Add missing va_end(3).
Ralph Corderoy [Sat, 9 Sep 2017 10:13:11 +0000 (11:13 +0100)]
content_error(): Add missing va_end(3).

A va_start(3) without a matching va_end() is undefined behaviour.

8 years agoSend a QUIT instead of RSET at session end when doing 'whom'.
Ken Hornstein [Fri, 8 Sep 2017 17:46:08 +0000 (13:46 -0400)]
Send a QUIT instead of RSET at session end when doing 'whom'.

When running 'whom -check' (which really invokes post(8)), at the
end of the SMTP session we would send a RSET instead of a QUIT.  This was
technically a RFC violation (RFC 5321 says a QUIT has to be the last
thing you send), and this would cause some SMTP servers to complain.
So make sure if we're being invoked by whom to send a QUIT at the end
of the session.  Reported by Ralph Corderoy.

8 years agoAdd a -credentials argument when we call post.
Ken Hornstein [Fri, 8 Sep 2017 16:08:41 +0000 (12:08 -0400)]
Add a -credentials argument when we call post.

If we are using -check, post(8) will need to talk to a remote SMTP server,
and it might need to perform authentication when doing so.  So include a
-credentials option if there is the appropriate line in the user's profile.

8 years agopopsbr.c: Remove impossible case from switch statement.
Ralph Corderoy [Fri, 8 Sep 2017 13:49:21 +0000 (14:49 +0100)]
popsbr.c: Remove impossible case from switch statement.

Actually, just convert the overkill switch statement into a couple of
if-statements as it's a lot less lines.

8 years agomhbuildsbr.c: Attempt fork(2) multiple times, as intended.
Ralph Corderoy [Fri, 8 Sep 2017 13:30:31 +0000 (14:30 +0100)]
mhbuildsbr.c: Attempt fork(2) multiple times, as intended.

The loop attempting fork() intends to try five times but the comparison
operator was wrong so would only try once.  Bug present since pre-git.

8 years agobase64.c: Don't out-of-bounds printf("%s", &encoded[-1]).
Ralph Corderoy [Fri, 8 Sep 2017 13:12:51 +0000 (14:12 +0100)]
base64.c: Don't out-of-bounds printf("%s", &encoded[-1]).

`cp' is walking through encoded[] when an error occurs and is stepped
back up to 20 elements to provide some lead-in context for the error
message.  If might be stepped back to encoded-1, but it attempts to cope
with that by `cp ? cp : encoded'.  cp is always non-NULL so true and cp
is printed.  Presumably, `cp > encoded' was meant.  But it's all a bit
of a rigmarole so just use min() instead to ensure cp stays within
encoded and print cp.  Fixes bfc6b93af.

8 years agocontent_error(): Don't strlen(invo_name) that might be NULL.
Ralph Corderoy [Fri, 8 Sep 2017 12:48:29 +0000 (13:48 +0100)]
content_error(): Don't strlen(invo_name) that might be NULL.

Earlier in content_error(), it checks invo_name isn't NULL before using
it.  Later, it passes it to strlen(3) without the check.  Either the
former is redundant or the latter wrong.  Rather than work out which,
delete the strlen(invo_name) because it was only used for a
variable-width indent on a second diagnostic line.  Instead, indent by a
fixed four spaces, which will look better when invo_name is stupidly
long anyway.  Bug present since pre-git.

8 years agoreplsbr.c: In parent, free child's argv[] built before fork().
Ralph Corderoy [Thu, 7 Sep 2017 09:36:56 +0000 (10:36 +0100)]
replsbr.c: In parent, free child's argv[] built before fork().

Fixes ccafa1944.

8 years agogetpass.c: Don't fileno(NULL) when fopen("/dev/tty") fails.
Ralph Corderoy [Thu, 7 Sep 2017 09:16:36 +0000 (10:16 +0100)]
getpass.c: Don't fileno(NULL) when fopen("/dev/tty") fails.

If stdin is a TTY, but opening it for writing fails, then stdin and
stderr are used as defaults and the TTY doesn't have echo disabled.  The
later test to restore echo just checks if stdin is a TTY and not that it
was opened successfully causing a NULL FILE pointer to be fileno(3)'d.
Fixes da6af9633.  This function's logic remains a bit contorted;  I went
for the minimal fix.

8 years agomhbuildsbr.c: Don't free(3) string then print it; do reverse.
Ralph Corderoy [Thu, 7 Sep 2017 09:03:25 +0000 (10:03 +0100)]
mhbuildsbr.c: Don't free(3) string then print it; do reverse.

Fixes c87ca5cca.