need help understaning a gdb error

Pages: 12
Dec 11, 2013 at 3:33pm
I am trying to make an illegal access? Is it possible that the bit pattern maybe there in
memory in the vector, but the vector is on the stack and hence out-of-scope by
the time control returns from the call?

Dec 11, 2013 at 3:54pm
This
1
2
3
4
5
6
7
8
9
10
uint16_t 
ldu1::lcf() const
{    
    int i;
    uint16_t lcf;
    printf("\n      LCF:  ");
    for(i=0; i<8; i++) cout << decoded_lcw_vec[i]; // how do you know that decoded_lcw_vec contains 8 entries? where does it come from?
    for(i=0; i<8; i++) lcf = decoded_lcw_vec[i];
    return lcf;
}
looks very dangerous.

At least change it like so:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
uint16_t 
ldu1::lcf() const
{    
    int i;
    uint16_t lcf = 0; // Note
    printf("\n      LCF:  ");
    for(i=0; i<decoded_lcw_vec.size(); i++)
{
 cout << decoded_lcw_vec[i];
lcf <<= 1;
//lcf |= decoded_lcw_vec[decoded_lcw_vec.size() - i - 1]; // most significant bit right
lcf |= decoded_lcw_vec[i]; // most significant bit left

}
    return lcf;
}
Last edited on Dec 11, 2013 at 4:14pm
Dec 11, 2013 at 5:54pm
this is how i know:
1
2
3
bit_vector decoded_lcw_vec(corrected_array, corrected_array + sizeof corrected_array / sizeof corrected_array[0]) ; 
    printf( "\n\n Decode LDU1 LCW Vector Complete:");
    for(int i = 0 ; i < 72; i++ )  cout << decoded_lcw_vec[i];    

gives output:

Decode LDU1 LCW Vector Complete:000000000000000001000000000000000000000000000001010011000100110101010001

the values are in the vector. so what you are saying is I should not be able to read only 8 of them at a time? the bits are in order. i know where that data payload is, but i am going to try what you have shown above; and I get a seg fault:

Program terminated with signal 11, Segmentation fault.
#0  0xb2d5e6f4 in ldu1::lcf (this=0x0) at ldu1.cc:136
136	    for(i=0; i<decoded_lcw_vec.size(); i++)
(gdb) bt
#0  0xb2d5e6f4 in ldu1::lcf (this=0x0) at ldu1.cc:136
#1  0xae9309b8 in ?? ()

Last edited on Dec 11, 2013 at 6:25pm
Dec 11, 2013 at 6:59pm
So, no matter how I try to do it, the program seg faults when trying to access the vector, out side of the function where it is filled. That vector should, at least I was under the impression it would, persist until the the class was destroyed. This means what? It has to be i am trying to make illegal access right? How can this be since I declared the vector private in the .h file and the class has not been destructed??
Last edited on Dec 11, 2013 at 7:02pm
Dec 11, 2013 at 8:14pm
the problem must be when filling the vector:
 
bit_vector decoded_lcw_vec(corrected_array, corrected_array + sizeof corrected_array / sizeof corrected_array[0]) ; 

i am putting the type before the name and so the compiler thinks the variable is local to that function. but if i take that type away, even though i declared it private in the .h file, i get this compile time error:

ldu1.cc:343:106: error: no match for call to '(bit_vector {aka std::vector<bool>}) (int [72], int*)'

what can be done here?
Last edited on Dec 11, 2013 at 8:14pm
Dec 11, 2013 at 8:44pm
bit_vector decoded_lcw_vec(corrected_array[0], corrected_array + sizeof corrected_array / sizeof corrected_array[0]); What was I thinking...
or
bit_vector decoded_lcw_vec(std::begin(corrected_array), std::end(corrected_array));
Last edited on Dec 11, 2013 at 9:21pm
Dec 11, 2013 at 9:00pm
i have no problem getting the values into the vector. the problem is the type 'bit_vector' in front of the the 'decoded_lcw_vec' . its making that variable local instead of a class variable.
Dec 11, 2013 at 9:19pm
density wrote:
i have no problem getting the values into the vector. the problem is the type 'bit_vector' in front of the the 'decoded_lcw_vec' . its making that variable local instead of a class variable.
I misunderstood, sorry.
If bit_vector decoded_lcw_vec(...) ; is in a function, then the decoded_lcw_vec you're copying to is local to that function.
If decoded_lcw_vec is already declared somewhere else and you want to re-fill it try...
std::copy(std::begin(corrected_array), std::end(corrected_array), decoded_lcw_vec.begin());

If I'm misunderstanding again, try posting more code, like where the vector is defined and where you are trying to fill it.
Last edited on Dec 11, 2013 at 9:24pm
Dec 11, 2013 at 9:29pm
it is declared private in the .h file. but it wont compile like that, i dont understand the error on compile:

 ldu1.cc: In member function 'void ldu1::correct_lcw(int*)': ldu1.cc:340:106: error: no match for call to '(bit_vector {aka std::vector<bool>}) (int [72], int*)' –

Thanks.
Dec 16, 2013 at 6:53pm
if i use a raw array instead of a vector the program works perfectly. I am just not understanding why declaring the typedef vector in the header gives a compile error.
Topic archived. No new replies allowed.
Pages: 12