473,796 Members | 2,618 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getting signal SEGV in my small program

56 New Member
I have written a file as below:

#include<stdio. h>
#include<string .h>
#include<stdlib .h>
int main()
{
char* items[2];
int i;
for(i=0;i<2;i++ )
{
char* temp = new char[11];
strcpy(temp,"AB CD EFGH");
items[i] = temp;
printf("items is:%u=%u\n",&it ems[i],items[i]);
printf("items is:%s\n",*temp) ;
}
printf("\n\nite ms is:%u\n",items) ;
printf("\nitems is:%u\n",&items );
items[2] = 0;
char** item_ptr = items;
while (*item_ptr != 0)
{
printf("item_pt r is:%u\n",*item_ ptr);
printf("item_pt r is:%u\n",**item _ptr);
printf("item_pt r is:%u\n",item_p tr);
printf("item_pt r is:%d\n",item_p tr);
item_ptr++;
}
return 0;
}

While I am compiling it, it gives segmentation fault:
Here I am pasting

(L)SUMV3/sparse/src/stk/dmg_meta_doc$ gcc ras1.cc
(L)SUMV3/sparse/src/stk/dmg_meta_doc$ ./a.out
items is:4026512392=1 65408
Segmentation Fault

Now I tried to debug that using dbx which is as below:

(L)SUMV3/sparse/src/stk/dmg_meta_doc$ dbx a.out
changes (topic)
The major new features of this release relative to 6.0 are:

o The dbx environment variable "cfront_demangl ing" has been removed.
The "-F" option to dbx (allow cfront-demangling) has also been removed.
Use an earlier version of dbx to get cfront support.
o This release continues to support Fortran intrinsics on Intel, even
though the Intel Fortran compiler was not shipped with WorkShop 6.
The next dbx release will not support Fortran intrinsics on Intel.

See also `help changes60'


To suppress this message, add the following line to your .dbxrc file:

dbxenv suppress_startu p_message 5.0
Reading a.out
dbx: warning: cannot demangle '__10bad_typeid '
dbx: warning: cannot demangle '__13bad_except ion'
dbx: warning: cannot demangle '__14__si_type_ infoPCcRC16__us er_type_info'
dbx: warning: cannot demangle '__16__user_typ e_infoPCc'
dbx: warning: cannot demangle '__17__class_ty pe_infoPCcPCQ21 7__class_type_i nfo9base_infoUi '
Reading ld.so.1
Reading libc.so.1
Reading libdl.so.1
Reading libc_psr.so.1
(dbx) where
dbx: program is not active
(dbx) run
Running: a.out
(process id 23331)
items is:4026512168=1 65408
signal SEGV (no mapping at the fault address) in strlen at 0xef6a53e4
0xef6a53e4: strlen+0x001c: ldub [%o1], %o3
(dbx) where
dbx: program is not active
(dbx) run
Running: a.out
(process id 23331)
items is:4026512168=1 65408
signal SEGV (no mapping at the fault address) in strlen at 0xef6a53e4
0xef6a53e4: strlen+0x001c: ldub [%o1], %o3
(dbx) where
=>[1] strlen(0x0, 0x41, 0x0, 0x1, 0x3a, 0xef72c8ac), at 0xef6a53e4
[2] _doprnt(0x16ceb , 0x0, 0x0, 0x41, 0x0, 0x0), at 0xef6dc834
[3] printf(0x16ce0, 0xef72d134, 0xef725930, 0xefffb328, 0x16c00, 0xef698ea8), at 0xef6e5990
[4] main(0x1, 0xefffb3a4, 0xefffb3ac, 0x28518, 0x0, 0x0), at 0x12538
(dbx) quit

Here it is showing that the error is in the function strlen. Which I didnot use. Rather I used strcpy().

Please let me know what is wrong in my program and how I will print the string
"AB CD EFGH".
Thanks in advance.
Aug 9 '07 #1
5 6077
JosAH
11,448 Recognized Expert MVP
char* temp = new char[11];
strcpy(temp,"AB CD EFGH");
printf("items is:%s\n",*temp) ;
This is definitely wrong; temp is a char* (a pointer to a char) so *temp is a char
and you can't treat it as if it were a char* (%s)

kind regards,

Jos

pa. the SIG_SEGV occurs during *runtime*, not during *compile* time.
Aug 9 '07 #2
rasmidas
56 New Member
So, can I write that as below:

char* temp = new char[11];
char buffer[11]="AB CD EFGH";
strcpy(temp,buf fer);

Please suggest me. Thanks.
Aug 9 '07 #3
JosAH
11,448 Recognized Expert MVP
So, can I write that as below:

char* temp = new char[11];
char buffer[11]="AB CD EFGH";
strcpy(temp,buf fer);

Please suggest me. Thanks.
That's not needed; it the following line that is wrong:

Expand|Select|Wrap|Line Numbers
  1. printf("items is:%s\n",*temp);
  2.  
Make it read like this:

Expand|Select|Wrap|Line Numbers
  1. printf("items is:%s\n",temp);
  2.  
kind regards,

Jos
Aug 9 '07 #4
rasmidas
56 New Member
One more question, In my program while debugging why
it is showing that the error is in the function strlen(). Which I didnot use. Rather I used strcpy(). Thanks.
Aug 10 '07 #5
JosAH
11,448 Recognized Expert MVP
One more question, In my program while debugging why
it is showing that the error is in the function strlen(). Which I didnot use. Rather I used strcpy(). Thanks.
Maybe you didn't call that function, but most likely the printf() function called it.

kind regards,

Jos
Aug 10 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
4312
by: Adi | last post by:
A java program we have written crashes with IBM JDK 1.3.1 on linux. It works fine on other platforms(Solaris,HPUx). It gets a SIGSERV Signal 11 and crashes just after few minutes after starting up. THe program creates a good number of threads. Any suggestions most welcome. Have tried following setting LD_ASSUME_KERNEL=2.2.5 disabling JIT by passing -Djava.compiler=NONE
10
2179
by: Chris | last post by:
Could anyone write a small program to log the Signal-to-Noise figures for a Netgear DG834 router? I have been getting very variable SNR readings - and I would like to collect some evidence to analyse. What is needed is a program that logs into the router's html page every minute, and then extracts the time and the SNR figure, and writes a line of a text file.
2
3095
by: Bram Stolk | last post by:
Hello, I catch SIGINT signals with a handler. In the handler, I use fd's to write some data to a child process. Is this valid? Because the data never arrives, and I wonder what I'm doing wrong. Can filedescriptors still be used when you're in the signal handling of SIGINT?
3
3526
by: Martin McCormick | last post by:
A C program contains several signal statements to remove a lock file if the program gets killed: /*Set up interrupt handler to catch ctrl-C so that lock file can be removed.*/ signal(SIGINT,crash); signal(SIGBUS,crash); signal(SIGSEGV,crash); This part works. Those signals cause the "crash.c" module to run and get rid of the lock. Is there a standard way to also print
11
2977
by: Jackie | last post by:
Hi everyone, I'd like to know when and how signals are used (e.g. SIGFPE, SIGABRT, SIGTERM, SIGSEGV, SIGINT)? Thank you so much.
2
2848
by: gnutuxy | last post by:
Hi, I am newbie in the Unix system programming and in learning phase. I usually read the libc manual and then try to implement small programs to test/check the learnt thing. I read the libc manual for signals and tried the program to check whether child inherits the signal handler intalled by parent befor fork.
26
4820
by: steve | last post by:
Well I've been working all morning and have finally found the source of my "bus error (signal 10)" errors. The source is odd. The error occurs in any function where I make the function call: (void)sprintf(ptr_testing, "This is my string"); This in itself isn't where the actual error occurs. The error occurs at any later point, in the same function where the sprintf() call is made, where I try to assign a value to one of the...
13
17728
by: vashwath | last post by:
Hi all, In my current project I am using signals for error handling. Since I cannot show full code, I have just shown important piece of code which is relevant. void sigsegenv() { printf("\n\n ********** F D S Message ***********\n\n"); printf("\n\n ********** S E G M E N T A T I O N F A U L T inside F D S ***********\n\n");
2
2863
by: rasmidas | last post by:
Hi, I am getting the following error while I am running my application. EXITING AddToEventLog() EXITING WriteNoDocProdEvent() EXITING SubstituteSummitMessages() EXITING dmgDocumentCreate () File: ssybdb12_imp.cc Line: 1484 CT_Library: ct_result() failed File: ssybdb12_imp.cc Line: 1484 Incorrect syntax near '132'. t@1 (l@1) signal SEGV (no mapping at the fault address) in GenerateDocument at 0xedda2ee4
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10187
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9055
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7553
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6795
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5578
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3735
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.