Thread: subscript of 2d array referencing address out of mapped region?

  1. #1
    Registered User
    Join Date
    Jan 2016
    Posts
    52

    subscript of 2d array referencing address out of mapped region?

    I am writing a program that iterates through large square arrays (reads only), it uses multiple threads to access different parts of the array in parallel. And when I have more than 1 thread working it will segfault with the following error:

    Code:
    ==17411== Process terminating with default action of signal 11 (SIGSEGV)
    ==17411==  Access not within mapped region at address 0x4
    ==17411==    at 0x1000021FA: avg_rows (jacobi.c:360)
    ==17411==    by 0x100447C12: _pthread_body (in /usr/lib/system/libsystem_pthread.dylib)
    ==17411==    by 0x100447B8F: _pthread_start (in /usr/lib/system/libsystem_pthread.dylib)
    ==17411==    by 0x100445374: thread_start (in /usr/lib/system/libsystem_pthread.dylib)
    here is the code for this loop:

    Code:
    for (uint32_t i = args->low; i < args->high+1; i++) {
            for (uint32_t j = 1; j < args->size+1; j++) {
                    float test = 0;
                    test = args->write[i][j];
                    test = args->read[i-1][j];
                    printf("%u, %u\n", j, i);
                    test = args->read[i+1][j]; //line 360
                    test = args->read[i][j-1];
                    test = args->read[i][j+1];
            }
    }
    This loop should iterate through all middle indexes of the array within the low/high row range given.

    The arrays that I am creating are of size
    Code:
    args->size+2
    which is why in the nested loop you see
    Code:
    j < args->size+1
    Also note that while I refer to these as 2d arrays, they are implemented as double pointers

    For this error the size of the array was 602x602 elements and the element being accessed was col 1, row 601. so this value is within the range of the array. Any thoughts on this, or ways to debug are greatly appreciated.

  2. #2
    Registered User
    Join Date
    Jan 2016
    Posts
    52
    After realizing that i was in fact incrementing higher than args->high, I was able to trace the error back to an integer overflow which was causing the value of args->high to be much higher than it should have been. Thanks to all that took the time to look over my problem.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I need C program uses a double-subscript array
    By the rockk in forum C Programming
    Replies: 6
    Last Post: 11-22-2014, 01:15 PM
  2. array subscript is not an integer
    By prathiksa in forum C Programming
    Replies: 8
    Last Post: 11-06-2012, 12:15 PM
  3. Changed to memory-mapped region not committing
    By Angus in forum Linux Programming
    Replies: 3
    Last Post: 02-24-2009, 11:27 AM
  4. Array subscript
    By poovizhipanpa in forum C Programming
    Replies: 6
    Last Post: 01-08-2009, 12:45 PM
  5. Copy region of bitmap to region of rectangle
    By Sfpiano in forum Windows Programming
    Replies: 2
    Last Post: 08-18-2007, 11:58 AM

Tags for this Thread