Re: Curious segmentation fault - please help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 5/13/06, Shriramana Sharma <samjnaa@xxxxxxxxx> wrote:
Attached: valgrind output; used electric fence too
Attached: original source code (licence: Artistic Licence v2)

I am getting a segmentation fault. I have compiled using electric fence, and
used valgrind to debug. (Not got used to gdb yet.)

For some reason, while I have initialized the array grahanaama[] (line 64 of
monthpan.c), grahanaama[0] gives an error at line 593 [added for debugging].
Similarly initialized array tithinaama does not give an error for accessing
tithinaama[0].

Looks like the function 'listsplpanchaanga' tries to access the
'grahanaama' array's nth element with only n - 1 being present
('vaasara = 6' accesses the last, 7th, element), thus causing a
segfault.  This is what valgrind means by an "Invalid read of size 1".
Make sure you do not read past the array by simply #defining a
constant like NUM_GRAHANAAMA and using an if-statement to check for
the correctness of 'vaasara', which is calculated dynamically on each
step in the loop.  Maybe you can simply correct the error by accessing
'grahanaama' using 'vaasara - 1': grahanaama[vaasara - 1] if this is
what you wanted to achieve.

At least, this is my first guess.  I have not yet fully grasped the
meaning of the code, due to difficulties in understanding the variable
and function names :-)

	\Steve
-
: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Assembler]     [Git]     [Kernel List]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [C Programming]     [Yosemite Campsites]     [Yosemite News]     [GCC Help]

  Powered by Linux