Re: [RFC PATCH v9 01/11] trace-cmd: Make ports unsigned int

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

 



On Tue,  2 Apr 2019 16:45:30 +0300
Slavomir Kaslev <kaslevs@xxxxxxxxxx> wrote:

> -static int write_ints(char *buf, size_t buf_len, int *arr, int arr_len)
> +static unsigned int atou(const char *s)
> +{
> +	long r;
> +
> +	r = atol(s);
> +	if (r >= 0 && r <= UINT_MAX)
> +		return r;
> +
> +	return 0;
> +}
> +

I wonder if we should do this instead:

/* test a to u */
static int tatou(const char *s, int *res)
{
	long r;

	r = atol(s);
	if (r >= 0 && r <= UINT_MAX) {
		*res = (unsigned)r;
		return 0;
	}
	return -1;
}

That way we could check for invalid ints.

-- Steve



[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux