Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date: Sun, 10 Feb 2013 20:23:27 +0400
From: Alexander Cherepanov <cherepan@...me.ru>
To: john-dev@...ts.openwall.com
Subject: Re: C for dummies

On 2013-02-09 02:30, Solar Designer wrote:
> magnum, Jim -
>
> On Fri, Feb 08, 2013 at 02:18:07PM -0600, jfoug wrote:
>> From: magnum [mailto:john.magnum@...hmail.com]
>>> In common.c we have several lines like this:
>>>
>>> char itoa16u[16] = "0123456789ABCDEF";
>>>
>>> Is this a bug or not?
>
> As I found out previously:
> In C, no.  In C++, yes.

For the record:

For C it's explicitly mentioned in K&R, section 8.7. C11 draft -- 
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf -- in 6.7.9 
Initialization, paragraph 14, contains the following:

   An array of character type may be initialized by a character string 
literal or UTF−8 string literal, optionally enclosed in braces. 
Successive bytes of the string literal (including the terminating null 
character if there is room or if the array is of unknown size) 
initialize the elements of the array.

Pay attention to the "if there is room" part. Then paragraph 32 contains 
an example of it: char t[3] = "abc";

OTOH C++ draft -- 
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3337.pdf -- in 
section 8.5.2 Character arrays [dcl.init.string], paragraph 2, says that 
it is a bug.

-- 
Alexander Cherepanov

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.