Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: [patch] give gpioctl.c some love



    Date:        Sat, 22 Aug 2015 02:22:00 +0200
    From:        Timo Buhrmester <fstd.lkml%gmail.com@localhost>
    Message-ID:  <20150822002200.GA12379@frozen.localdomain>

With the possible exception of the added consts, I also don't
like any of the suggested changes - I tend to write "if (p)"
myself often, but that's because I'm lazy - if someone else has
typed the "!= NULL" part, I'd never waste time removing it.

But while most of the changes are just objectionable, this part
is just plain funny (and sad...)

  | +static unsigned
  | +get_uint_or_die(const char *str, const char *name)
  | +{
  | +	int oerrno;
  | +	char *ep;
  | +
  | +	long lval = strtol(str, &ep, 0);
  | +	if (!*str || *ep)
  | +		errx(EXIT_FAILURE, "invalid %s (not a number)", name);
  | +
  | +	oerrno = errno, errno = 0;
  | +
  | +	if ((errno == ERANGE && (lval == LONG_MAX || lval == LONG_MIN))
  | +	    || lval < 0 || (unsigned long)lval > UINT_MAX)
  | +		errx(EXIT_FAILURE, "%s out of range", name);
  | +
  | +	errno = oerrno;
  | +
  | +	return (unsigned)lval;
  | +}

Clearly that was never really tested (or even read checked), was it?

kre


Home | Main Index | Thread Index | Old Index