Message ID | 1477965641-95206-4-git-send-email-nickcooper-zhangtonghao@opencloud.tech |
---|---|
State | Accepted |
Delegated to: | Guru Shetty |
Headers | show |
On 31 October 2016 at 19:00, nickcooper-zhangtonghao < nickcooper-zhangtonghao@opencloud.tech> wrote: > Signed-off-by: nickcooper-zhangtonghao <nickcooper-zhangtonghao@ > opencloud.tech> > Can you tell why one is better than the other? > --- > lib/packets.c | 11 ++++------- > 1 file changed, 4 insertions(+), 7 deletions(-) > > diff --git a/lib/packets.c b/lib/packets.c > index 990c407..1d2d452 100644 > --- a/lib/packets.c > +++ b/lib/packets.c > @@ -436,15 +436,12 @@ char * OVS_WARN_UNUSED_RESULT > ip_parse_port(const char *s, ovs_be32 *ip, ovs_be16 *port) > { > int n = 0; > - if (!ovs_scan_len(s, &n, IP_PORT_SCAN_FMT, > - IP_PORT_SCAN_ARGS(ip, port))) { > - return xasprintf("%s: invalid IP address or port number", s); > + if (ovs_scan(s, IP_PORT_SCAN_FMT"%n", IP_PORT_SCAN_ARGS(ip, port), &n) > + && !s[n]) { > + return NULL; > } > > - if (s[n]) { > - return xasprintf("%s: invalid IP address or port number", s); > - } > - return NULL; > + return xasprintf("%s: invalid IP address or port number", s); > } > > /* Parses string 's', which must be an IP address with an optional > netmask or > -- > 1.8.3.1 > > > > _______________________________________________ > dev mailing list > dev@openvswitch.org > http://openvswitch.org/mailman/listinfo/dev >
Hi Guru Shetty I folded in the following minor incremental just because ovs_scan_len() is only really meant for situations where the 'n' offset is being incremented over several calls. Thanks. Nick > On Nov 19, 2016, at 2:35 AM, Guru Shetty <guru@ovn.org> wrote: > > Can you tell why one is better than the other? > > --- > lib/packets.c | 11 ++++------- > 1 file changed, 4 insertions(+), 7 deletions(-) > > diff --git a/lib/packets.c b/lib/packets.c > index 990c407..1d2d452 100644 > --- a/lib/packets.c > +++ b/lib/packets.c > @@ -436,15 +436,12 @@ char * OVS_WARN_UNUSED_RESULT > ip_parse_port(const char *s, ovs_be32 *ip, ovs_be16 *port) > { > int n = 0; > - if (!ovs_scan_len(s, &n, IP_PORT_SCAN_FMT, > - IP_PORT_SCAN_ARGS(ip, port))) { > - return xasprintf("%s: invalid IP address or port number", s); > + if (ovs_scan(s, IP_PORT_SCAN_FMT"%n", IP_PORT_SCAN_ARGS(ip, port), &n) > + && !s[n]) { > + return NULL; > } > > - if (s[n]) { > - return xasprintf("%s: invalid IP address or port number", s); > - } > - return NULL; > + return xasprintf("%s: invalid IP address or port number", s); > }
diff --git a/lib/packets.c b/lib/packets.c index 990c407..1d2d452 100644 --- a/lib/packets.c +++ b/lib/packets.c @@ -436,15 +436,12 @@ char * OVS_WARN_UNUSED_RESULT ip_parse_port(const char *s, ovs_be32 *ip, ovs_be16 *port) { int n = 0; - if (!ovs_scan_len(s, &n, IP_PORT_SCAN_FMT, - IP_PORT_SCAN_ARGS(ip, port))) { - return xasprintf("%s: invalid IP address or port number", s); + if (ovs_scan(s, IP_PORT_SCAN_FMT"%n", IP_PORT_SCAN_ARGS(ip, port), &n) + && !s[n]) { + return NULL; } - if (s[n]) { - return xasprintf("%s: invalid IP address or port number", s); - } - return NULL; + return xasprintf("%s: invalid IP address or port number", s); } /* Parses string 's', which must be an IP address with an optional netmask or
Signed-off-by: nickcooper-zhangtonghao <nickcooper-zhangtonghao@opencloud.tech> --- lib/packets.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)