public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/54454] New: gcc violates c99 specification w.r.t. flexible arrays
@ 2012-09-02 1:36 mikulas at artax dot karlin.mff.cuni.cz
2012-09-02 1:53 ` [Bug c/54454] " mikulas at artax dot karlin.mff.cuni.cz
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: mikulas at artax dot karlin.mff.cuni.cz @ 2012-09-02 1:36 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54454
Bug #: 54454
Summary: gcc violates c99 specification w.r.t. flexible arrays
Classification: Unclassified
Product: gcc
Version: 4.7.1
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: c
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: mikulas@artax.karlin.mff.cuni.cz
Host: hppa-linux-gnu
Target: hppa-linux-gnu
Build: hppa-linux-gnu
The c99 specification says (section 6.7.2.1, paragraph 16): "The size of the
structure [with flexible array member] shall be equal to the offset of the
last element of an otherwise identical structure that replaces the flexible
array member with an array of unspecified length". This is not true in gcc.
Try to complile and run this program: the size of the structure with the
flexible array member is 8. However, offset of the flexible array member is 6.
According to the specification, sizeof(struct flexible) should be 6.
#include <stdio.h>
#include <stddef.h>
struct flexible {
unsigned a;
unsigned short b;
unsigned char array[];
};
struct not_flexible {
unsigned a;
unsigned short b;
unsigned char array[1];
};
int main(void)
{
printf("sizeof(struct flexible) = %d\n", (int)sizeof(struct flexible));
printf("offsetof(struct not_flexible, array)) = %d\n",
(int)offsetof(struct not_flexible, array));
printf("offsetof(struct flexible, array)) = %d\n", (int)offsetof(struct
flexible, array));
return 0;
}
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/54454] gcc violates c99 specification w.r.t. flexible arrays
2012-09-02 1:36 [Bug c/54454] New: gcc violates c99 specification w.r.t. flexible arrays mikulas at artax dot karlin.mff.cuni.cz
@ 2012-09-02 1:53 ` mikulas at artax dot karlin.mff.cuni.cz
2012-09-02 2:06 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: mikulas at artax dot karlin.mff.cuni.cz @ 2012-09-02 1:53 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54454
--- Comment #1 from mikulas at artax dot karlin.mff.cuni.cz 2012-09-02 01:52:54 UTC ---
Another specification violation:
section 6.7.2.1 paragraph 20 says that assignment of a structure with flexible
array member doesn't copy any of the array elements. In gcc it is buggy because
it copies some array elements.
Try this:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct flexible {
unsigned a;
unsigned short b;
unsigned char array[];
};
int main(void)
{
struct flexible *f1, *f2;
f1 = malloc(sizeof(struct flexible) + 3);
f1->array[0] = 0;
f1->array[1] = 0;
f1->array[2] = 0;
f2 = malloc(sizeof(struct flexible) + 3);
f2->array[0] = 1;
f2->array[1] = 1;
f2->array[2] = 1;
*f2 = *f1;
printf("f2->array[0] == %d (should be 1)\n", f2->array[0]);
printf("f2->array[1] == %d (should be 1)\n", f2->array[1]);
printf("f2->array[2] == %d (should be 1)\n", f2->array[2]);
return 0;
}
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/54454] gcc violates c99 specification w.r.t. flexible arrays
2012-09-02 1:36 [Bug c/54454] New: gcc violates c99 specification w.r.t. flexible arrays mikulas at artax dot karlin.mff.cuni.cz
2012-09-02 1:53 ` [Bug c/54454] " mikulas at artax dot karlin.mff.cuni.cz
@ 2012-09-02 2:06 ` pinskia at gcc dot gnu.org
2012-09-02 12:20 ` jsm28 at gcc dot gnu.org
2024-03-14 20:20 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-09-02 2:06 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54454
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-09-02 02:05:47 UTC ---
I think this comes down to alignment.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/54454] gcc violates c99 specification w.r.t. flexible arrays
2012-09-02 1:36 [Bug c/54454] New: gcc violates c99 specification w.r.t. flexible arrays mikulas at artax dot karlin.mff.cuni.cz
2012-09-02 1:53 ` [Bug c/54454] " mikulas at artax dot karlin.mff.cuni.cz
2012-09-02 2:06 ` pinskia at gcc dot gnu.org
@ 2012-09-02 12:20 ` jsm28 at gcc dot gnu.org
2024-03-14 20:20 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: jsm28 at gcc dot gnu.org @ 2012-09-02 12:20 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54454
Joseph S. Myers <jsm28 at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
--- Comment #3 from Joseph S. Myers <jsm28 at gcc dot gnu.org> 2012-09-02 12:20:39 UTC ---
All the text you are quoting changed in TC2 following DR 282.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/54454] gcc violates c99 specification w.r.t. flexible arrays
2012-09-02 1:36 [Bug c/54454] New: gcc violates c99 specification w.r.t. flexible arrays mikulas at artax dot karlin.mff.cuni.cz
` (2 preceding siblings ...)
2012-09-02 12:20 ` jsm28 at gcc dot gnu.org
@ 2024-03-14 20:20 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-14 20:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54454
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|INVALID |DUPLICATE
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup.
*** This bug has been marked as a duplicate of bug 9058 ***
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-03-14 20:20 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-02 1:36 [Bug c/54454] New: gcc violates c99 specification w.r.t. flexible arrays mikulas at artax dot karlin.mff.cuni.cz
2012-09-02 1:53 ` [Bug c/54454] " mikulas at artax dot karlin.mff.cuni.cz
2012-09-02 2:06 ` pinskia at gcc dot gnu.org
2012-09-02 12:20 ` jsm28 at gcc dot gnu.org
2024-03-14 20:20 ` pinskia at gcc dot gnu.org
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).