Bug 800804 - Warn when using multidimensional zero length array
Warn when using multidimensional zero length array
Status: CLOSED WONTFIX
Product: Fedora
Classification: Fedora
Component: gcc (Show other bugs)
15
Unspecified Unspecified
unspecified Severity unspecified
: ---
: ---
Assigned To: Jakub Jelinek
Fedora Extras Quality Assurance
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2012-03-07 05:10 EST by Markus Mayer
Modified: 2012-08-07 12:25 EDT (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2012-08-07 12:25:40 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Markus Mayer 2012-03-07 05:10:28 EST
Description of problem:
GCC allows to declare arrays of zero length (a[0]). When using this the user is responsible to use the array correctly (accourding its bounds: a[3]=0).When using multidimensional arrays of zero length (a[0][0]), it is imposible to use it correctly (a[3][6]=0), because gcc is unable to calculate the correct offset.

Please print an error or a warning, when using multidimensional zero length arrays.

Version-Release number of selected component (if applicable):
4.6.1
gcc-4.6.1-9.fc15.i686


How reproducible:
Compile this with 'gcc -Wall':
------------------------------
#include "string.h"
#include "stdio.h"

int main(void)
{
    union
    {
        char a[0][0];
        char b[16];
    } u;

    strcpy( u.b, "0123456789");

    unsigned int i = 0;
    unsigned int j = 0;
    for( i = 0; i < 4; ++i)
    {
        for( j = 0; j < 4; ++j)
        {
            printf("[%d][%d]: %c\n", i, j, u.a[i][j]);
        }
    }

    return 0;
}
------------------------------

Actual results:
[0][0]: 0
[0][1]: 1
[0][2]: 2
[0][3]: 3
[1][0]: 0
[1][1]: 1
[1][2]: 2
[1][3]: 3
[2][0]: 0
[2][1]: 1
[2][2]: 2
[2][3]: 3
[3][0]: 0
[3][1]: 1
[3][2]: 2
[3][3]: 3

Numbers from 0 to 9 are expected, but it is impossible for gcc to figure this out.

Expected results:
An error or at least a warning, that using multidimensional zero length arrays is a bad idea.
Comment 1 Fedora End Of Life 2012-08-07 12:25:42 EDT
This message is a notice that Fedora 15 is now at end of life. Fedora
has stopped maintaining and issuing updates for Fedora 15. It is
Fedora's policy to close all bug reports from releases that are no
longer maintained. At this time, all open bugs with a Fedora 'version'
of '15' have been closed as WONTFIX.

(Please note: Our normal process is to give advanced warning of this
occurring, but we forgot to do that. A thousand apologies.)

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, feel free to reopen
this bug and simply change the 'version' to a later Fedora version.

Bug Reporter: Thank you for reporting this issue and we are sorry that
we were unable to fix it before Fedora 15 reached end of life. If you
would still like to see this bug fixed and are able to reproduce it
against a later version of Fedora, you are encouraged to click on
"Clone This Bug" (top right of this page) and open it against that
version of Fedora.

Although we aim to fix as many bugs as possible during every release's
lifetime, sometimes those efforts are overtaken by events. Often a
more recent Fedora release includes newer upstream software that fixes
bugs or makes them obsolete.

The process we are following is described here:
http://fedoraproject.org/wiki/BugZappers/HouseKeeping

Note You need to log in before you can comment on or make changes to this bug.