From: "André Goddard Rosa" <andre.goddard-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Cc: linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [patch] strcpy.3: Avoid redundantly filling the position 'n - 1' two times in strncpy() example code
Date: Wed, 24 Sep 2008 11:01:34 -0300 [thread overview]
Message-ID: <200809241101.34334.andre.goddard@gmail.com> (raw)
In-Reply-To: <200809210310.43647.andre.goddard-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
[-- 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
next prev parent reply other threads:[~2008-09-24 14:01 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-21 6:10 [patch] tsearch.3: dispose properly of allocated resources in example code André Goddard Rosa
[not found] ` <200809210310.43647.andre.goddard-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2008-09-23 6:28 ` Michael Kerrisk
[not found] ` <cfd18e0f0809222328r599e22c1je0f4261ee969bca8-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-09-23 13:23 ` André Goddard Rosa
[not found] ` <b8bf37780809230623k62d43d6cgf11af4820566cd2d-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-09-23 13:56 ` Michael Kerrisk
2008-09-24 14:01 ` [patch] hsearch.3: Call hdestroy() after using hash table created by hcreate(), for the sake of completeness André Goddard Rosa
[not found] ` <200809241101.23128.andre.goddard-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2008-09-25 8:04 ` Michael Kerrisk
2008-09-24 14:01 ` André Goddard Rosa [this message]
[not found] ` <200809241101.34334.andre.goddard-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2008-09-25 8:14 ` [patch] strcpy.3: Avoid redundantly filling the position 'n - 1' two times in strncpy() example code Michael Kerrisk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200809241101.34334.andre.goddard@gmail.com \
--to=andre.goddard-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox