9front - general discussion about 9front
 help / color / mirror / Atom feed
From: tlaronde@polynum.com
To: 9front@9front.org
Subject: Re: [9front] strndup should use strnlen and memcpy
Date: Fri, 18 Dec 2020 12:29:14 +0100	[thread overview]
Message-ID: <20201218112914.GA717@polynum.com> (raw)
In-Reply-To: <54874114B98195307A5780FB707F9115@gmail.com>

On Fri, Dec 18, 2020 at 11:31:22AM +0100, Sigrid Solveig HaflC-nudC3ttir wrote:
> > Open Group does not specify if arg1 should be null terminated or not.
> > https://pubs.opengroup.org/onlinepubs/9699919799/functions/strdup.html
> 
> "Applications should not assume that strndup() will allocate ( size + 1)
> bytes when strlen(s) is smaller than size."
> 
> Pretty sure this means it's supposed to be null-terminated, or
> otherwise it wouldn't mention the "dangerous" strlen right there.

As I read it---but I'm not an english native speaker---this only means
that one shall not infer that the allocation will be len + 1 (since if
the string is shorter, it will be less). This does not say anything
about a terminating '\0' and this is precisely the purpose to copy some
amount of chars in a null terminated array of chars (the dup will be
null terminated; it is not a requirement of the chars array duplicated).
the name could have been mem2nstr (fixed maximum size length str as a 
result, not as an argument).
-- 
        Thierry Laronde <tlaronde +AT+ polynum +dot+ com>
                     http://www.kergis.com/
                    http://kertex.kergis.com/
                       http://www.sbfa.fr/
Key fingerprint = 0FF7 E906 FBAF FE95 FD89  250D 52B1 AE95 6006 F40C

  parent reply	other threads:[~2020-12-18 11:34 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-18  8:22 Xiao-Yong Jin
2020-12-18  8:38 ` Sigrid Solveig Haflínudóttir
2020-12-18  9:01   ` tlaronde
2020-12-18  9:59     ` Sigrid Solveig Haflínudóttir
2020-12-18 10:21       ` Kemal
2020-12-18 10:31         ` Sigrid Solveig Haflínudóttir
2020-12-18 10:48           ` Kemal
2020-12-18 11:02             ` Eli Cohen
2020-12-18 11:05               ` Eli Cohen
2020-12-18 11:29           ` tlaronde [this message]
2020-12-18 11:37             ` Sigrid Solveig Haflínudóttir
2020-12-18 11:43               ` Eli Cohen
2020-12-18 11:50               ` Kemal
2020-12-18 11:55                 ` Eli Cohen
2020-12-18 12:06                   ` Kemal
2020-12-18 13:22                   ` José Miguel Sánchez García
2020-12-18 14:34           ` Devon H. O'Dell
2020-12-18 14:26       ` Devon H. O'Dell
2020-12-18 15:27 ` ori

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=20201218112914.GA717@polynum.com \
    --to=tlaronde@polynum.com \
    --cc=9front@9front.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;
as well as URLs for NNTP newsgroup(s).