[LLVMbugs] [Bug 21596] 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.

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Nov 18 09:46:40 PST 2014


http://llvm.org/bugs/show_bug.cgi?id=21596

            Bug ID: 21596
           Summary: 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.
           Product: clang
           Version: 3.5
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: release blocker
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: jendas1 at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

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

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20141118/635144c7/attachment.html>


More information about the llvm-bugs mailing list