<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Add warning if array initializer contains less elements than declared"
   href="https://llvm.org/bugs/show_bug.cgi?id=25599">25599</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Add warning if array initializer contains less elements than declared
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>samjnaa@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Consider this small program arr.c:

#include <stdio.h>
const int len = 3;
const char * arr[len] = {"a", "b", "c"};
int main() { for (int i = 0; i < len; ++i) printf("%c ", arr[i][0]);
putchar('\n'); }

If I include excess elements in the array:

const char * arr[len] = {"a", "b", "c", "d"};

Clang warns me though it is harmless:

$ clang -o arr arr.c && ./arr
arr.c:3:41: warning: excess elements in array initializer
const char * arr[len] = {"a", "b", "c", "d"};
                                        ^~~
1 warning generated.
a b c

But if there are less elements:

const char * arr[len] = {"a", "b"};

Clang doesn't warn me and it segfaults:

$ clang -o arr arr.c && ./arr
Segmentation fault (core dumped)

I realize it is the fault of the programmer to deref the pointer without
checking its validity, but the point of a warning is to be helpful, and so I
request that Clang may produce a warning in such cases.

Thanks.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>