All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH iproute2] tunnel: Return constant string without copying it
@ 2018-01-12 17:49 Serhey Popovych
  2018-01-18 14:08 ` Serhey Popovych
  0 siblings, 1 reply; 2+ messages in thread
From: Serhey Popovych @ 2018-01-12 17:49 UTC (permalink / raw)
  To: netdev

We return constant string from tnl_strproto(), no need
to copy it to temporary buffer and then return such
buffer as const: return constant string instead.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
---
 ip/tunnel.c |   25 +++++++------------------
 1 file changed, 7 insertions(+), 18 deletions(-)

diff --git a/ip/tunnel.c b/ip/tunnel.c
index f860103..946a36c 100644
--- a/ip/tunnel.c
+++ b/ip/tunnel.c
@@ -39,33 +39,22 @@
 
 const char *tnl_strproto(__u8 proto)
 {
-	static char buf[16];
-
 	switch (proto) {
 	case IPPROTO_IPIP:
-		strcpy(buf, "ip");
-		break;
+		return "ip";
 	case IPPROTO_GRE:
-		strcpy(buf, "gre");
-		break;
+		return "gre";
 	case IPPROTO_IPV6:
-		strcpy(buf, "ipv6");
-		break;
+		return "ipv6";
 	case IPPROTO_ESP:
-		strcpy(buf, "esp");
-		break;
+		return "esp";
 	case IPPROTO_MPLS:
-		strcpy(buf, "mpls");
-		break;
+		return "mpls";
 	case 0:
-		strcpy(buf, "any");
-		break;
+		return "any";
 	default:
-		strcpy(buf, "unknown");
-		break;
+		return "unknown";
 	}
-
-	return buf;
 }
 
 int tnl_get_ioctl(const char *basedev, void *p)
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH iproute2] tunnel: Return constant string without copying it
  2018-01-12 17:49 [PATCH iproute2] tunnel: Return constant string without copying it Serhey Popovych
@ 2018-01-18 14:08 ` Serhey Popovych
  0 siblings, 0 replies; 2+ messages in thread
From: Serhey Popovych @ 2018-01-18 14:08 UTC (permalink / raw)
  To: netdev


[-- Attachment #1.1: Type: text/plain, Size: 1450 bytes --]

Serhey Popovych wrote:

> We return constant string from tnl_strproto(), no need
> to copy it to temporary buffer and then return such
> buffer as const: return constant string instead.
> 
> Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>

This change should be ignored: now it is a part of series
of patches with cover letter subject:

  "ip/tunnel: Improve tunnel parameters printing"

since v2.

> ---
>  ip/tunnel.c |   25 +++++++------------------
>  1 file changed, 7 insertions(+), 18 deletions(-)
> 
> diff --git a/ip/tunnel.c b/ip/tunnel.c
> index f860103..946a36c 100644
> --- a/ip/tunnel.c
> +++ b/ip/tunnel.c
> @@ -39,33 +39,22 @@
>  
>  const char *tnl_strproto(__u8 proto)
>  {
> -	static char buf[16];
> -
>  	switch (proto) {
>  	case IPPROTO_IPIP:
> -		strcpy(buf, "ip");
> -		break;
> +		return "ip";
>  	case IPPROTO_GRE:
> -		strcpy(buf, "gre");
> -		break;
> +		return "gre";
>  	case IPPROTO_IPV6:
> -		strcpy(buf, "ipv6");
> -		break;
> +		return "ipv6";
>  	case IPPROTO_ESP:
> -		strcpy(buf, "esp");
> -		break;
> +		return "esp";
>  	case IPPROTO_MPLS:
> -		strcpy(buf, "mpls");
> -		break;
> +		return "mpls";
>  	case 0:
> -		strcpy(buf, "any");
> -		break;
> +		return "any";
>  	default:
> -		strcpy(buf, "unknown");
> -		break;
> +		return "unknown";
>  	}
> -
> -	return buf;
>  }
>  
>  int tnl_get_ioctl(const char *basedev, void *p)
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 490 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-01-18 14:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-12 17:49 [PATCH iproute2] tunnel: Return constant string without copying it Serhey Popovych
2018-01-18 14:08 ` Serhey Popovych

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.