473,466 Members | 1,416 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

strncpy gives core dump

3 New Member
I am getting coredump at strncpy whats the matter and solution can anyone figure out . Its urgent please help
I am pasting code which give coredump.


2 #include <stdio.h>
3 #include <string.h>
4
5 int main ()
6 {
7 char *value = "To be or not to be";
8 char const *newValue = "Hello";
9
10 size_t newSize, valueSize;
11 newSize = newValue ? ( strlen( newValue ) + 1 ) : 1;
12
13 valueSize = 9;
14
15 if( newSize > 1 )
16 {
17
18 if( value )
19 {
20
21 free( value );
22 value = NULL;
23 }
24
25 value = (char *)malloc(newSize);
26 if( value )
27 valueSize = newSize;
28 else
29 valueSize = 0;
30 }
31
32 if( newValue == NULL )
33 {
34 if( value )
35 *value = '\0';
36 }
37 else
38 {
39
40 strncpy( value, newValue, newSize );
value[ newSize - 1 ] = '\0';
42 }
43
44
45
46 /* str2 = (char *)malloc(8);
47 strncpy(str2,str1,3);
48 str2[3]='\0';*/
49 printf("empty string : ");
50 puts (value);
51 printf(" after string : ");
52 return 0;
53 }
Oct 30 '09 #1
1 2765
sumeshnb
13 New Member
there is an error at the following line..
21 free( value ); - you cannot free a statically allocated memory
Oct 30 '09 #2

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

Similar topics

1
by: Martin | last post by:
I use dbx and i got the following error: Reading GL_CliConnMgr core file header read successfully Reading ld.so.1 dbx: core file read error: address 0xff3e6000 not available dbx: core file...
10
by: ken | last post by:
hello, i'm writing a c program on a linux system. i'm debugging a segmentation fault but i don't want it to dump a core file because the memory footprint of the program is over 300Mb and i don't...
10
by: John Liu | last post by:
We upgraded from 7.2 to 7.4, it looks like everything working, but when I issue a query such as select * from tab (tab has about 2-3 million records), it causes core dump. I tuned some the...
3
by: John Liu | last post by:
AIX pg version 7.4 Select * from document2 core dump. Did a few more experiments with select * from document2 limit... I limit to 500000 it works, 600000 it exits but says "calloc:...
10
by: wong_powah | last post by:
I want to find out where (which line) my C program core dump. How to do that? Is there a web site describing the procedure? One approach is to use stack trace of the mdb debugger, but I does not...
14
by: Sheldon | last post by:
Hi, I have a python script that uses a C extention. I keep getting a recurring problem that causes a core dump a few lines after the C extention return data back tp python. I tried using pbd and...
9
by: Ron | last post by:
#define MAX_SIZE 512 char mybuffer; void myfunction( const char* src ) { if( src == null ) { return; } /* A core dump is occuring here */ strncpy( mybuffer, src, MAX_SIZE );
2
by: molayos | last post by:
I am getting core dump on strncpy on the following code. I could get strncpy to work only with array and not with pointer. Can somebody take a look at this code and suggest me why its core dump in...
5
by: johnericaturnbull | last post by:
Hi - I am very new to python. I get this random core dump and am looking for a good way to catch the error. I know the function my core dump occurs. Is there any error catching/handling that I...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.