]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd: fix aspath parsing 1309/head
authorVincent JARDIN <vincent.jardin@6wind.com>
Mon, 9 Oct 2017 07:43:26 +0000 (09:43 +0200)
committerVincent JARDIN <vincent.jardin@6wind.com>
Mon, 9 Oct 2017 07:48:53 +0000 (09:48 +0200)
clang provides a notice about it that this p++ is useless,
because ++ would be done after the return.

From code review, I understand that p shall be incremented
for each token that is parsed from the buf. So let's keep
this intent.

Note that this commit is changing the behaviour of the source
code since from now p++ will be returned instead of p.
However, it does not hurt since the only consumer
just free() the aspath if it is parsed as as_token_unknown.
Let's be safe with a proper execution flow from now.

PS:
C reminders:

int f7(void) {
  int j = 7;

  return ++j; // return 8
}

int f8(void) {
  int j = 7;

  return j++; // return 7
}

Signed-off-by: Vincent Jardin <vincent.jardin@6wind.com>
bgpd/bgp_aspath.c

index 2b776d218277ce7eadd2675d3288a1c6845cbfac..6c03ba30596834279385cc0ccf143ef9600ed3f8 100644 (file)
@@ -1914,7 +1914,8 @@ static const char *aspath_gettoken(const char *buf, enum as_token *token,
 
        /* There is no match then return unknown token. */
        *token = as_token_unknown;
-       return p++;
+       p++;
+       return p;
 }
 
 struct aspath *aspath_str2aspath(const char *str)