[patch] strcpy.3: Avoid redundantly filling the position 'n - 1' two times in strncpy() example code

André Goddard Rosa
2008-09-24T14:01:34Z

[-- Attachment #1: Type: text/plain, Size: 980 bytes --]

From 88a02845c606413444bfb055935303b4896d0271 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Andr=C3=A9=20Goddard=20Rosa?= <andre.goddard@gmail.com>
Date: Wed, 24 Sep 2008 10:25:08 -0300
Subject: [PATCH] Avoid redundantly filling the position 'n - 1' two times in strncpy() example code.
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

When we use 'strncpy(buf, str, n)', strncpy() will fill chars from 0..(n - 1).
As we force the character at position 'n - 1' to be '\0' anyway, don't fill it in strncpy() before.

Signed-off-by: André Goddard Rosa <andre.goddard@gmail.com>
---
man3/strcpy.3 | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/man3/strcpy.3 b/man3/strcpy.3
index 7a8091f..d2e08a3 100644
--- a/man3/strcpy.3
+++ b/man3/strcpy.3
@@ -115,7 +115,7 @@ as follows:
.in +4n
.nf

-strncpy(buf, str, n);
+strncpy(buf, str, n \- 1);
if (n > 0)
buf[n \- 1]= \(aq\\0\(aq;
.fi
--
1.6.0.2.508.g24593

\0

[-- Attachment #2: 0001-Avoid-redundantly-filling-the-position-n-1-two-t.patch --]
[-- Type: text/x-patch, Size: 1040 bytes --]

From 88a02845c606413444bfb055935303b4896d0271 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Andr=C3=A9=20Goddard=20Rosa?= <andre.goddard@gmail.com>
Date: Wed, 24 Sep 2008 10:25:08 -0300
Subject: [PATCH] Avoid redundantly filling the position 'n - 1' two times in strncpy() example code.
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

When we use 'strncpy(buf, str, n)', strncpy() will fill chars from 0..(n - 1).
As we force the character at position 'n - 1' to be '\0' anyway, don't fill it in strncpy() before.

Signed-off-by: André Goddard Rosa <andre.goddard-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
man3/strcpy.3 | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/man3/strcpy.3 b/man3/strcpy.3
index 7a8091f..d2e08a3 100644
--- a/man3/strcpy.3
+++ b/man3/strcpy.3
@@ -115,7 +115,7 @@ as follows:
.in +4n
.nf

-strncpy(buf, str, n);
+strncpy(buf, str, n \- 1);
if (n > 0)
buf[n \- 1]= \(aq\\0\(aq;
.fi
--
1.6.0.2.508.g24593