Fgets Bus Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the bus error 10 c++ company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions linux bus error core dumped Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million how to solve bus error in linux programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Bus Error: 10 in C up vote 0 down vote favorite My code compiles just fine but when I run sigbus it I get bus error: 10 void backupf(char *namelist, char *dirname) { char *in_filename; char *out_filename; char line[MAXPATHLEN]; FILE *filenames = fopen(namelist, "r"); if(filenames == NULL) { fprintf(stderr, "Cannot Open File\n"); exit(EXIT_FAILURE); } while( fgets(line, sizeof line, filenames) != NULL ) { sprintf(in_filename, "./%s\n", line); sprintf(out_filename, "%s/%s\n", dirname, line); } backup(dirname, in_filename, out_filename); fclose(filenames); } It's supposed to take a text file argument with a list of file names and then use that
Segmentation Fault 11
information to back it up to a backup directory using a backup function I've written. c backup bus-error share|improve this question edited Nov 2 '13 at 2:54 Jonathan Leffler 439k62511823 asked Nov 2 '13 at 2:46 SecretlyHuman 33 Welcome to Stack Overflow. Please read the About page soon. Does the crash occur in backup() because you don't properly check that the files it uses are opened successfully? You should state what happens, and you should be able to use a debugger enough to get a stack trace so you can tell which function it crashed in (even if you can't do anything else with it). You really don't want to add newlines to the file names; you probably need to remove the newlines that fgets() leaves on the data it reads. And learning how to use print statements to find out what is going on is also important. –Jonathan Leffler Nov 2 '13 at 2:50 i know it crashes in the fgets() function, the backup function is fine –SecretlyHuman Nov 2 '13 at 2:53 Odd...that tends to mean you have a buffer overflow in one of the functions this code calls. Also odd is the fact that you don't call backup in the loop; you only try saving the last name that
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it http://stackoverflow.com/questions/19738440/bus-error-10-in-c only takes a minute: Sign up What is a bus error? up vote 156 down vote favorite 49 What does the "bus error" message mean, and how does it differ from a segfault? c unix segmentation-fault bus-error share|improve this question edited Oct 18 '15 at 10:44 Cool Guy 15.7k51952 asked Oct 17 '08 at 14:48 raldi 7,252216178 add a comment| http://stackoverflow.com/questions/212466/what-is-a-bus-error 15 Answers 15 active oldest votes up vote 151 down vote accepted Bus errors are rare nowadays on x86 and occur when your processor cannot even attempt the memory access requested, typically: using a processor instruction with an address that does not satisfy its alignment requirements. Segmentation faults occur when accessing memory which does not belong to your process, they are very common and are typically the result of: using a pointer to something that was deallocated. using an uninitialized hence bogus pointer. using a null pointer. overflowing a buffer. PS: To be more precise this is not manipulating the pointer itself that will cause issues, it's accessing the memory it points to (dereferencing). share|improve this answer edited Oct 17 '08 at 15:18 answered Oct 17 '08 at 15:12 bltxd 5,72322336 52 They aren't rare; I'm just at Exercise 9 from How to Learn C the Hard Way and already encountered one... –11684 Mar 26 '13 at 20:12 5 Another cause of bus errors (on Linux anyway) is when the operating system can't back a virtua
Search Username Password Remember Me? Register Lost Password? facebook google twitter rss Free Web Developer Tools Advanced Search Forum Programming Languages http://forums.devshed.com/programming/449468-fix-bus-error-post1822954.html C Programming How to fix bus error? Thread: How to fix bus error? Share This Thread Tweet This + 1 this Post To Linkedin Subscribe to this Thread Subscribe to This Thread June 2nd, 2007,04:38 PM #1 No Profile Picture Tifa View Profile View Forum Posts Registered User Devshed Newbie (0 bus error - 499 posts) Join Date Sep 2006 Posts 20 Rep Power 0 How to fix bus error? This is what i have. ADT.h(below) ADT.c (after 2nd line) ----------------------------------------------------------- Code: #include