public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Chen Gang <gang.chen.5i5j@gmail.com>
To: Chung-Lin Tang <cltang@codesourcery.com>,
	 Chung-Lin Tang <chunglin_tang@mentor.com>,
	Jeff Law <law@redhat.com>,
	sandra@codesourcery.com
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] gcc/config/nios2/nios2.c: Let custom_builtin_name[*] always be zero terminated string
Date: Sat, 26 Jul 2014 11:45:00 -0000	[thread overview]
Message-ID: <53D38631.4010307@gmail.com> (raw)
In-Reply-To: <53D36FD7.1070505@codesourcery.com>

On 07/26/2014 05:07 PM, Chung-Lin Tang wrote:
> On 2014/7/26 03:33 PM, Chen Gang wrote:
>> On 07/26/2014 02:32 PM, Chung-Lin Tang wrote:
>>> On 14/7/26 11:28 AM, Chen Gang wrote:
>>>> The related strncpy() for custom_builtin_name[*] may set 5 none-zero
>>>> characters, which may cause custom_builtin_name[*] is none-zero
>>>> terminated.
>>>>
>>>> So add additional '\0' byte for custom_builtin_name[*].
>>>
>>> Where did you see this? Supposedly the snprintf of the custom function
>>> type string should at most be of 'xnxx' format; 4 characters at most,
>>
>> I guess, your 'xnxx' means "%cn%c%c", not "%sn%s%s" (which is current
>> implementation), also at present, "32 - n" is 17, not 4 for snprintf()
>> length limitation.
> 
> The use of %sn%s%s is intentional. That allows me to print "" directly
> using snprintf.
> 

OK, thanks.

> '32 - n' is to represent the rest of the 32-byte buffer, harmless
> really, as it is at most 4 chars.
> 
> Also, if I were to restrict it in the snprintf argument, it would be 5
> (including the null char) not 4.
> 

OK, thanks. And for me, I'd like to use 'sizeof(custom_builtin_name[0])'
instead of "32 - n" for snprintf().


>> If we are always sure it must be no more than 4 characters (at present,
>> it is, but in the future, I don't know). We can use strcpy() instead of
>> strncpy() for it -- that will let other readers no doubt.
>>
>> If we need let custom_builtin_name[*] not only zero terminated, but also
>> zero pad, we need pass '4' to strncpy() instead of '5', that also will
>> clear all doubts.
> 
> I don't understand what point you're trying to make here, really. As
> Andreas has noted in the other mail, strncpy does zero-termination
> automatically.
> 

strncpy will zero pad, but not be sure of the dest string will be zero
terminated, please "man strncpy" to get more details.

So for me, I'd like to use '4' instead of '5' for strncpy(), that will
clear all doubts (although, at present, it is not a bug, so this patch
can be skipped, if we are only focus on bug fix).


Thanks.
-- 
Chen Gang

Open, share, and attitude like air, water, and life which God blessed

  reply	other threads:[~2014-07-26 10:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-26  4:44 Chen Gang
2014-07-26  7:04 ` Chung-Lin Tang
2014-07-26  7:59   ` Chen Gang
2014-07-26  8:59     ` Andreas Schwab
2014-07-26 10:43       ` Chen Gang
2014-07-26  9:10     ` Chung-Lin Tang
2014-07-26 11:45       ` Chen Gang [this message]
  -- strict thread matches above, loose matches on Subject: below --
2014-07-26  3:28 Chen Gang

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=53D38631.4010307@gmail.com \
    --to=gang.chen.5i5j@gmail.com \
    --cc=chunglin_tang@mentor.com \
    --cc=cltang@codesourcery.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=law@redhat.com \
    --cc=sandra@codesourcery.com \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).