All of lore.kernel.org
 help / color / mirror / Atom feed
From: Shriramana Sharma <samjnaa@gmail.com>
To: Linux C Programming List <linux-c-programming@vger.kernel.org>
Subject: Re: Curious segmentation fault - please help
Date: Sat, 13 May 2006 21:57:19 +0530	[thread overview]
Message-ID: <200605132157.24997.samjnaa@gmail.com> (raw)
In-Reply-To: <6a00c8d50605130809pba67862gd981f8bf0fa6927f@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2311 bytes --]

Saturday 13 May 2006 20:39 samaye, Steve Graegert alekhiit:

> 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), 

Yep. But the array does contain 7 elements. Vide line 64 of monthpan.c:

char *grahanaama[] = {"Bhaanu", "Soma", "Mangala", "Budha", "Guru", "Shukra", 
"Shani"};

[celestialbodyname[] = "Sun", "Moon", "Mars", "Mercury", "Jupiter", "Venus", 
"Saturn" -- for weekday]

> thus causing a 
> segfault.  

... so how can a segfault be caused? As you see the valgrind-output, 

debug: vaasara = 1, graha =    Soma
debug: vaasara = 2, graha = Mangala
debug: vaasara = 3, graha =   Budha
debug: vaasara = 4, graha =    Guru
debug: vaasara = 5, graha =  Shukra
debug: vaasara = 6, graha =   Shani

vaasara[6] does give the correct output. The fault is seen *after* vaasara[6] 
is read and written to stdout:

==9675== Invalid read of size 1
==9675==  Address 0x726956 is not stack'd, malloc'd or (recently) free'd
==9675==
==9675== Process terminating with default action of signal 11 (SIGSEGV)
==9675==  Access not within mapped region at address 0x726956
==9675==    by 0x40A5C92: printf (in /lib/libc-2.4.so)
==9675==    by 0x8049B7D: listsplpanchaanga (monthpan.c:593)
debug: vaasara = 0, graha = ==9675==

(Trimmed)

> 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.

But then I would not get grahanaama[0] = "Surya" which is what I want to get. 
Actually this program compiled and worked perfectly on GCC 4.02 with SUSE 
10.0. (And also GCC 4.1 with SUSE 10.0 I think.) But since I upgraded to SUSE 
10.1, I get this error. SUSE 10.1 has gcc 4.1 and glibc 2.4, [as I am sure 
you as a fellow suser know] if that means anything...

> 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 :-)

Sanskrit. It's an ancient-Indian-astronomy application.

-- 

Tux #395953 resides at http://samvit.org
playing with KDE 3.51 on SUSE Linux 10.1
$ date [] CCE +2006-05-13 W19-6 UTC+0530

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

  reply	other threads:[~2006-05-13 16:27 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
2006-05-13 16:27   ` Shriramana Sharma [this message]
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=200605132157.24997.samjnaa@gmail.com \
    --to=samjnaa@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.