<html>
<head>
<base href="http://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 --- - Pointer to an address returned from function does not correlate to pointer to address in function. This causes access to different place in memory, than was expected."
href="http://llvm.org/bugs/show_bug.cgi?id=21596">21596</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Pointer to an address returned from function does not correlate to pointer to address in function. This causes access to different place in memory, than was expected.
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.5
</td>
</tr>
<tr>
<th>Hardware</th>
<td>Macintosh
</td>
</tr>
<tr>
<th>OS</th>
<td>MacOS X
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>release blocker
</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>jendas1@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>Version of llvm:
Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn)
Code that shows the error:
#include <stdio.h>
#include <stdlib.h>
int ** create_2d_array (int size) {
int ** array = (int **)malloc(sizeof(int)*size);
printf("Address: 0x%llx\n", (long long) &array);
for (int i = 0; i < size; i++) {
array[i] = (int *)malloc(sizeof(int)*size);
for (int j = 0; j < size; j++) {
array[i][j] = 100;
printf("%5d ", array[i][j]);
}
printf("\n");
}
return array;
}
void print_2d_array(int ** array, int size) {
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
printf("%5d ", array[i][j]);
}
printf("\n");
}
}
int main(int argc, const char * argv[]) {
int ** array = create_2d_array(3);
printf("Address: 0x%llx\n", (long long) &array);
print_2d_array(array, 3);
return 0;
}
Expected output is:
Address: something
100 100 100
100 100 100
100 100 100
Address: something
100 100 100
100 100 100
100 100 100
I've got:
Address: 0x7fff5fbff760
100 100 100
100 100 100
100 100 100
Address: 0x7fff5fbff788
1070432 1 100
100 100 100
100 100 100</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>