test_read_matrix Illegal Memory Access

42 views
Skip to first unread message

Hareet

unread,
Oct 28, 2020, 7:09:17 PM10/28/20
to cmpt-295-sfu
SFU ID: hareetd
Github username: hareetd
Line and file: Unsure about the line but file is either read_matrix or test_read_matrix
Expected behavior: Print matrix to screen
Observed behavior: See attached image
Question:
 When I run test_read_matrix it results in an illegal memory access. I've double-checked that im using the correct pointers returned by malloc and loading the rows/cols from them properly but I still can't figure out what's wrong.
error.png

Hareet

unread,
Oct 28, 2020, 7:49:22 PM10/28/20
to cmpt-295-sfu
Edit: I stepped through the code and instead of an illegal access error I exit with error code 1 because fopen fails (file descriptor is returned as 0xFFFFFFFF). 

Arrvindh Shriraman

unread,
Oct 28, 2020, 8:10:06 PM10/28/20
to cmpt-295-sfu
Your a1; number of rows is wrong when you call print_int_array
It is 20. It should be 3. Check your read_matrix and see whether you are reading the number of rows correctly and storing into that pointer

Arrvindh Shriraman

unread,
Oct 28, 2020, 8:11:29 PM10/28/20
to cmpt-295-sfu
Check file path or whether you passed the file name correctly. Either way your issue is within read matrix not the file opening

Hareet

unread,
Oct 28, 2020, 8:49:37 PM10/28/20
to cmpt-295-sfu
Thank you I figured it out. I was forgetting to multiply by sizeof(int) when passing number of bytes into malloc. 
Reply all
Reply to author
Forward
0 new messages