Operating System - Linux
1752734 Members
5580 Online
108789 Solutions
New Discussion

Getting core dump while dealing with TRY/CATCH exceptions in HP-UX 11V2

 
sasikala
Advisor

Getting core dump while dealing with TRY/CATCH exceptions in HP-UX 11V2


Problem Description:
Getting core dump while dealing with TRY/CATCH exceptions in HP-UX 11V2.

Below is the sample test program to verify the TRY/CATCH exceptional handling calls.

#include
#include
/* prototyping of functions */
/* to allow type checks by */
/* the compiler */
#include
#include


void main()
{
int n;
char string[50];
/* strcpy(a,b) copies string b into a */
/* defined via the stdio.h header */
strcpy(string, "Hello World");

/* call own function */
n = n_char(string);
printf("Length of string = %d\n", n);
}

/* definition of local function n_char */
int n_char(char string[])
{
/* local variable in this function */
int n;
/* strlen(a) returns the length of */
/* string a */
/* defined via the string.h header */
TRY
printf("HAI \n");
CATCH_ALL
printf("CATCH_ALL \n");
ENDTRY
n = strlen(string);
if (n > 50)
printf("String is longer than 50 characters\n");

/* return the value of integer n */
return n;
}

Compilation option given : cc -ldcekt test.c..

Though the compilation went fine, execution is failed with 'core dump' error.

:cc -ldcekt test.c
:a.out
Memory fault(coredump)

While debugging with gdb, found that it fails while calling 'TRY'. Below is the gdb output :

Program received signal SIGSEGV, Segmentation fault
si_code: 2 - SEGV_ACCERR - Invalid Permissions for object.
0x4000e40:0 in n_char () at test.c:35
35 TRY


Could you please let me know if compilation option needs to be changed to avoid getting 'core dump'?

Thanks in advance for your help.
1 REPLY 1
Dennis Handly
Acclaimed Contributor

Re: Getting core dump while dealing with TRY/CATCH exceptions in HP-UX 11.23

Not that this is your direct problem:
char string[50];

This will only take a string of 49 bytes, plus the null character.

if (n > 50)

corruption has already occurred if the string is 50 bytes.

Program received signal SIGSEGV, Segmentation fault Invalid Permissions for object.
0x4000e40:0 in n_char () at test.c:35
35 TRY

You might want to preprocess this file so you can see what the TRY macro does. Compile with -E and save stdout.


>Could you please let me know if compilation option needs to be changed to avoid getting 'core dump'?

I don't know of any.