TransWikia.com

c - Access not within mapped region error

Stack Overflow Asked by RHCP_Lean on January 9, 2021

I’m having a problem with my program. When I execute it with valgrind, the following message appears:

==4626== Process terminating with default action of signal 11 (SIGSEGV)
==4626==  Access not within mapped region at address 0x8068FA0
==4626==    at 0x8048C36: read_event (events.c:76)
==4626==    by 0x8048653: main (main.c:65)

Am I assigning an invalid value to message? line 76 is message[0] = value

The function read_event() is the following:

bool read_event(FILE *f, event_t *event, char *channel, int *lenght, uint8_t *message){
        uint8_t value = read_uint8(f);
        if(decode_event(value, event, channel, lenght)){
                for(size_t i = 0; i < *lenght; i++)
                        message[i] = read_uint8(f);
                return true;
        } else {
                message[0] = value; //line 76
                for(size_t i = 1; i < *lenght; i++)
                        message[i] = read_uint8(f);
                return true;
        }
}

I already tested the functions decode_event() and read_uint8() in other program so I know they aren’t causing any problem.

My main function is:

#include <stdio.h>
#include <stdint.h>

#define MAX_LONG 5
int main(int argc, char *argv[]){
        FILE *f = fopen(argv[1], "rb");
        //...
        event_t event;
        char channel;
        int lenght;
        uint8_t buffer[MAX_LONG];

        if(! read_event(f, &event, &channel, &lenght, buffer)) { //program crashes here
                fprintf(stderr, "Cant read the event!n");
                fclose(f);
                return 1;
        }
        // ...
        fclose(f);
        return 0;
}

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP