Re: A couple of style(9) tweaks

2015-10-22 Thread Philip Guenther
On Tue, Oct 20, 2015 at 3:55 PM, Ilya Kaliman  wrote:
...
> --- bin/ed/main.c   9 Oct 2015 21:24:05 -   1.53
> +++ bin/ed/main.c   20 Oct 2015 22:49:53 -
> @@ -174,7 +174,7 @@ top:
> signal(SIGHUP, signal_hup);
> signal(SIGQUIT, SIG_IGN);
> signal(SIGINT, signal_int);
> -   if (status = sigsetjmp(env, 1)) {
> +   if ((status = sigsetjmp(env, 1))) {

This technically undefined behavior, as you are not allowed to capture
the return value of setjmp(), _setjmp(), or sigsetjmp() in a variable
To quote the C standard:

An application shall ensure that an invocation of setjmp( ) appears in
one of the following
contexts only:

· The entire controlling expression of a selection or iteration statement

· One operand of a relational or equality operator with the other
operand an integral
   constant expression, with the resulting expression being the
entire controlling expression
   of a selection or iteration statement

· The operand of a unary '!' operator with the resulting
expression being the entire
   controlling expression of a selection or iteration

· The entire expression of an expression statement (possibly cast to void)

If the invocation appears in any other context, the behavior is undefined.


POSIX extends that to the other two functions.


Fortunately, ed only call sigsetjmpt() with the value -1, and status
is initialized to zero, so the diff below should fix it without
changing the behavior.

oks?

Philip Guenther

--- bin/ed/main.c   21 Oct 2015 16:06:57 -  1.54
+++ bin/ed/main.c   23 Oct 2015 04:55:31 -
@@ -174,7 +174,8 @@ top:
signal(SIGHUP, signal_hup);
signal(SIGQUIT, SIG_IGN);
signal(SIGINT, signal_int);
-   if ((status = sigsetjmp(env, 1))) {
+   if (sigsetjmp(env, 1)) {
+   status = -1;
fputs("\n?\n", stderr);
seterrmsg("interrupt");
} else {



A couple of style(9) tweaks

2015-10-20 Thread Ilya Kaliman
===
RCS file: /cvs/src/bin/ed/main.c,v
retrieving revision 1.53
diff -u -p -r1.53 main.c
--- bin/ed/main.c   9 Oct 2015 21:24:05 -   1.53
+++ bin/ed/main.c   20 Oct 2015 22:49:53 -
@@ -174,7 +174,7 @@ top:
signal(SIGHUP, signal_hup);
signal(SIGQUIT, SIG_IGN);
signal(SIGINT, signal_int);
-   if (status = sigsetjmp(env, 1)) {
+   if ((status = sigsetjmp(env, 1))) {
fputs("\n?\n", stderr);
seterrmsg("interrupt");
} else {
Index: usr.bin/rcs/co.c
===

===
RCS file: /cvs/src/usr.bin/rcs/co.c,v
retrieving revision 1.121
diff -u -p -r1.121 co.c
--- usr.bin/rcs/co.c13 Jun 2015 20:15:21 -  1.121
+++ usr.bin/rcs/co.c20 Oct 2015 22:52:04 -
@@ -515,7 +515,7 @@ checkout_err_nobranch(RCSFILE *file, con
file->rf_path,
date ? " a date before " : "",
date ? date : "",
-   author ? " and author " + (date ? 0:4 ) : "",
+   author ? " and author " + (date ? 0:4) : "",
author ? author : "",
state  ? " and state " + (date || author ? 0:4) : "",
state  ? state : "");
Index: usr.bin/who/who.c
===

===
RCS file: /cvs/src/usr.bin/who/who.c,v
retrieving revision 1.26
diff -u -p -r1.26 who.c
--- usr.bin/who/who.c   12 Oct 2015 19:56:47 -  1.26
+++ usr.bin/who/who.c   20 Oct 2015 22:52:04 -
@@ -77,7 +77,7 @@ main(int argc, char *argv[])
if (pledge("stdio rpath getpw", NULL) == -1)
err(1, "pledge");

-   if (mytty = ttyname(0)) {
+   if ((mytty = ttyname(0))) {
/* strip any directory component */
if ((t = strrchr(mytty, '/')))
mytty = t + 1;