LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-23-2010, 10:32 PM   #1
golmschenk
Member
 
Registered: Nov 2009
Posts: 144

Rep: Reputation: 15
C - strncpy segfault


At "strncpy(pathname,fullname,pathname_length);" we're getting a segfault and we're not quite sure why. In our case checked with gdb at the time filename is test25.txt and pathname_length is 6 and fullname is /test/test25.txt. Any Suggestions?

Code:
#include <Kernel.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
static const String PROGRAM_NAME = "rm";
int main(int argc,char **argv) 
{
	Kernel::initialize();
	DirectoryEntry *directoryEntry = new DirectoryEntry();
	int x=0;
	int status = 0;
	String fullname = argv[1];
	String filename = strrchr(fullname,'/')+1;
	String pathname;
	size_t pathname_length = strlen(fullname) - strlen(filename);
	fprintf(stderr,"pathname_length:%d\n",pathname_length);
	strncpy(pathname,fullname,pathname_length);
	...
	...
If you need any more information to help us let us know. Thanks!
 
Old 07-23-2010, 10:39 PM   #2
golmschenk
Member
 
Registered: Nov 2009
Posts: 144

Original Poster
Rep: Reputation: 15
Whoops! Teehee. String class has different commands then regular char arrays don't they? I think we've got it now. Thanks!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Segfault on several software Vassos Linux - Software 5 09-20-2008 07:16 AM
strncpy function definition required lokeshmaremalla Programming 6 11-29-2006 10:42 PM
Gate 88 segfault t3gah Linux - Games 1 03-21-2005 04:07 AM
grep, ln both segfault TexasDex Linux - Software 1 03-20-2005 05:46 PM
diff between strcpy and strncpy djgerbavore Programming 11 08-04-2004 07:01 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration