View Issue Details

IDProjectCategoryView StatusLast Update
00009181003.1(2013)/Issue7+TC1System Interfacespublic2019-06-10 08:54
Reportersafinaskar Assigned To 
PrioritynormalSeverityEditorialTypeError
Status ClosedResolutionAccepted 
NameAskar Safin
Organization
User Reference
Sectiongetaddrinfo
Page Number2013 edition, p. 927
Line Number31262
Interp Status---
Final Accepted Text
Summary0000918: C99 forbids "struct addrinfo hints = {}"
Description-
Desired Action-31262 struct addrinfo hints = {};
+31262 struct addrinfo hints = {0};
Tagstc2-2008

Relationships

related to 0000934 Closed Requirement for zeroing the sockaddr_in and sockaddr_un structures. 
related to 0000939 Closed Clarify getaddrinfo() hints initialisation 

Activities

geoffclare

2015-02-05 09:59

manager   bugnote:0002535

In addition to the problem raised here, there are a couple of problems with the related text on Page 924 Line 31149, "In this hints structure every member other than ai_flags, ai_family, ai_socktype, and ai_protocol shall be set to zero or a null pointer."

1. This is intended to be a requirement on the application, and so should be worded as "The application shall ensure that ..."

2. It is not clear whether "every member" refers only to the standard members or includes any non-standard additional members. I.e. can applications just set the standard members explicitly and leave any non-standard additional members with indeterminate values, or do they have to use a form of initialisation (as in the example) that implicitly sets all non-standard additional members to zero/null?

jilles

2015-02-06 14:52

reporter   bugnote:0002538

The proposed initializer causes a compiler warning (missing initializer) at strict settings (-Wall -Wextra) of gcc and clang. The compilers do not complain if a designated initializer is used, like:

struct addrinfo hints = { .ai_flags = 0 };

The following four lines can be folded into the initializer as well:

struct addrinfo hints = { .ai_family = AF_UNSPEC, .ai_socktype = SOCK_DGRAM, .ai_flags = AI_PASSIVE };

safinaskar

2015-02-06 17:57

reporter   bugnote:0002539

Missing initializer is just a warning, "hints = {0}" still confirms to C99. But "hints = {.ai_flags = 0}" is bad, for example, because it is not supported in C++, even in C++14

dalias

2015-02-06 19:23

reporter   bugnote:0002540

Last edited: 2015-04-23 15:10

The warning mentioned in note 0002538 should be fixed as part of the resolution of gcc bug 53119 ( https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119 ). If it's not, this should be reported. {0} is the correct idiomatic "universal zero initializer" especially for types whose details are not specified, and compilers should not be discouraging its use. For example it's the only portable way to initialize mbstate_t.

safinaskar

2015-02-06 23:51

reporter   bugnote:0002541

gcc 4.9.2 already doesn't report this warning (gcc 4.9.2-10 in Debian).

(and dalias, please, put space after links, your link now points to non-existent bug number "53119)")

safinaskar

2015-02-07 00:13

reporter   bugnote:0002542

Same bug in clang: http://llvm.org/bugs/show_bug.cgi?id=21689

Don Cragun

2015-04-23 16:33

manager   bugnote:0002636

An additional bug will be filed to address the issues raised in 0000918:0002535.

Issue History

Date Modified Username Field Change
2015-02-04 22:17 safinaskar New Issue
2015-02-04 22:17 safinaskar Name => Askar Safin
2015-02-04 22:17 safinaskar Section => getaddrinfo
2015-02-04 22:17 safinaskar Page Number => 2013 edition, p. 927
2015-02-04 22:17 safinaskar Line Number => 31262
2015-02-05 09:59 geoffclare Note Added: 0002535
2015-02-06 14:52 jilles Note Added: 0002538
2015-02-06 17:57 safinaskar Note Added: 0002539
2015-02-06 19:23 dalias Note Added: 0002540
2015-02-06 23:51 safinaskar Note Added: 0002541
2015-02-07 00:13 safinaskar Note Added: 0002542
2015-04-20 08:47 geoffclare Relationship added related to 0000934
2015-04-23 15:10 rhansen Note Edited: 0002540
2015-04-23 16:30 Don Cragun Interp Status => ---
2015-04-23 16:30 Don Cragun Status New => Resolved
2015-04-23 16:30 Don Cragun Resolution Open => Accepted
2015-04-23 16:30 Don Cragun Tag Attached: tc2-2008
2015-04-23 16:33 Don Cragun Note Added: 0002636
2015-04-24 09:06 geoffclare Relationship added related to 0000939
2019-06-10 08:54 agadmin Status Resolved => Closed