linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Steve Graegert" <graegerts@gmail.com>
To: linux-c-programming@vger.kernel.org
Subject: Re: Curious segmentation fault - please help
Date: Sat, 13 May 2006 17:09:08 +0200	[thread overview]
Message-ID: <6a00c8d50605130809pba67862gd981f8bf0fa6927f@mail.gmail.com> (raw)
In-Reply-To: <200605131958.39156.samjnaa@gmail.com>

On 5/13/06, Shriramana Sharma <samjnaa@gmail.com> 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

  reply	other threads:[~2006-05-13 15:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-13 14:28 Curious segmentation fault - please help Shriramana Sharma
2006-05-13 15:09 ` Steve Graegert [this message]
2006-05-13 16:27   ` Shriramana Sharma
2006-05-13 17:20     ` Steve Graegert
2006-05-13 18:58       ` Shriramana Sharma
2006-05-13 21:04         ` Steve Graegert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6a00c8d50605130809pba67862gd981f8bf0fa6927f@mail.gmail.com \
    --to=graegerts@gmail.com \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).