From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephen Hemminger Subject: Re: [PATCH 1/1] net/mlx4: add port parameter Date: Fri, 10 Mar 2017 08:34:59 -0800 Message-ID: <20170310083459.6c1aeac7@xeon-e3> References: <70A7408C6E1BFB41B192A929744D8523968EC82E@ALA-MBC.corp.ad.wrs.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: Gaetan Rivet , "dev@dpdk.org" , Adrien Mazarguil , Nelio Laranjeiro To: "Legacy, Allain" Return-path: Received: from mail-pf0-f180.google.com (mail-pf0-f180.google.com [209.85.192.180]) by dpdk.org (Postfix) with ESMTP id 246462C01 for ; Fri, 10 Mar 2017 17:35:02 +0100 (CET) Received: by mail-pf0-f180.google.com with SMTP id j5so43683241pfb.2 for ; Fri, 10 Mar 2017 08:35:02 -0800 (PST) In-Reply-To: <70A7408C6E1BFB41B192A929744D8523968EC82E@ALA-MBC.corp.ad.wrs.com> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Fri, 10 Mar 2017 16:24:32 +0000 "Legacy, Allain" wrote: > The robustness of the strtoul() could be improved with something like the= following to catch non-integer characters following the port number.=20 >=20 > char *end =3D NULL; > tmp =3D strtoull(val, &end, 0); > if ((val[0] =3D=3D '\0') || (end =3D=3D NULL) || (*end !=3D '\0') || = (errno !=3D 0)) Extra () no necessary here. Also errno is not set unless the return value is ULLONG_MAX. It will be last value. Something like: tmp =3D strtoull(val, &end, 0); if (!*val || !*end || (tmp =3D=3D ULLONG_MAX && errno)) ... If endptr is not NULL, strtoul() stores the address of the fi= rst invalid character in *endptr. If there were no digits at all, s= tr=E2=80=90 toul() stores the original value of nptr in *endptr (and returns = 0). In particular, if *nptr is not '\0' but **endptr is '\0' on return, = the entire string is valid. ... RETURN VALUE The strtoul() function returns either the result of the conversion = or, if there was a leading minus sign, the negation of the result of = the conversion represented as an unsigned value, unless the original (n= on=E2=80=90 negated) value would overflow; in the latter case, strtoul() retu= rns ULONG_MAX and sets errno to ERANGE. Precisely the same holds for s= tr=E2=80=90 toull() (with ULLONG_MAX instead of ULONG_MAX).