Re: Curious segmentation fault - please help

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

 



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: pgpMmXmyyL3Pl.pgp
Description: PGP signature


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

  Powered by Linux