<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 --- - #including files from /sys on Linux adds extra null characters" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D24168&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=l_wOxVKO8ZmU9r8bS6wx-ynR2eEmDTZ9ANJsH8FeBGg&s=BArdykvXbDLc7sV6I7ufnUf4WAdyXjjyS-XcPtNlVUs&e=">24168</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>#including files from /sys on Linux adds extra null characters
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </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>unassignedclangbugs@nondot.org
          </td>
        </tr>

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

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Hello,

I recently encountered a bug where #including files from /sys on Linux will
read extra null characters that are not originally in that file.

The bug can be reproduced by #including any file from /sys, for example:

bug.c:
    #include "/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size"

This makes clang generate about several thousand warnings about null
characters:

/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size:2:1968: warning: 
      null character ignored [-Wnull-character

However, if you run something like cat
/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size you see that the
file does not have all these extra null characters. On my machine cat cat
/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size just prints out
"64".

So somehow the preprocessor is reading many more null characters than are
actually in the file. Now of course there's probably no practical reason to
#include files from /sys, but still it should read the file in correctly
without appending extra null bytes.

I think the preprocessor is not correctly reading the file from the sysfs
virtual file system on /sys.

I am running clang version 3.5.0 on Linux kernel 4.0.6.</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>