🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #6019

warning about missing struct elements

#6019
From: Bruno Haible
Date: Fri, 03 Jan 1997 00:00
61 lines
2323 bytes

Hi,

This is not a bug report, just a suggestion for a new warning.
When a structure is initialized from a bracketed list {.., .., ..},
if fewer initializers are given than structure elements, the remaining
elements are initialized to 0.

It would be nice if gcc would allow to check when this occurs, through
a special warning option (not implied in -Wall).

When programming with structures of function pointers, missing function
pointers at the end are especially nasty, because they cause a core dump
and gdb is not able to give a stack backtrace.
Example:

================================= foo.c ===================================
#include <stdlib.h>

struct vtable {
	void* (* _malloc) (size_t);
	void (* _free) (void*);
	void* (* _realloc) (void*, size_t);
};

struct vtable mtable = {
	malloc,
	free
};

int main ()
{
	void* p = mtable._malloc(10);
	p = mtable._realloc(p,20);
	return 0;
}
===========================================================================

$ gcc -v
Reading specs from /usr/lib/gcc-lib/i486-linux/2.7.2/specs
gcc version 2.7.2

$ gcc -O -g -Wall foo.c             or      $ gcc -O -g -Wall -x c++ foo.c
$ ./a.out
Segmentation fault (core dumped)
$ gdb a.out
(gdb) run
Starting program: /home/bruno/a.out 
Program received signal SIGSEGV, Segmentation fault.
0x0 in ?? ()
(gdb) where
#0  0x0 in ?? ()


----------------------------------------------------------------------------
Bruno Haible                            net: <haible@ilog.fr>
ILOG S.A.                               tel: +33 1 4908 3585
9, rue de Verdun - BP 85                fax: +33 1 4908 3510
94253 Gentilly Cedex                    url: http://www.ilog.fr/
France                                  url: http://www.ilog.com/
Technical Details
Message-ID: <6a23281abc80bf6352efd7862ecffffe@wretched.mailer.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 113d02,92ef973d59440f5b,start
X-Google-Attributes: gid113d02,public
From: haible@ilog.fr (Bruno Haible)
Subject: warning about missing struct elements
Date: 1997/01/03
Message-ID: <6a23281abc80bf6352efd7862ecffffe@wretched.mailer.com>
X-Deja-AN: 207526367
sender: bug-gcc-request@prep.ai.mit.edu
x-gateway: wendy-fate.uu.net from bug-gcc to gnu.gcc.bug; Fri, 3 Jan 1997 13:00:01 EST
return-path: <gnulists-usenet-ownrr@prep.ai.mit.edu>
newsgroups: gnu.gcc.bug