Sponsored Content
Top Forums Programming fread: segementation fault(coredump) w/o stdlib.h Post 302287084 by shamrock on Thursday 12th of February 2009 05:57:39 PM
Old 02-12-2009
There is a mistake in my explanation...sizeof(buffer) will be 4 or 8 bytes depending on whether the system is 32/64 bits so printf output is correct...
Code:
printf ("\n size of buffer %ld, length of file %d\n ", sizeof(buffer), lSize);

Since sizeof pointer on a 64 bit system is 8 bytes. But that doesn't mean that memory is malloced for it.
What is still confusing is that control never passes to this statement below...
Code:
if (buffer == NULL) {fputs ("Memory error",stderr); exit (2);}

So do as jim suggested and run it through a symbolic debugger compiled with the -g switch.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Coredump (memory fault)

We are running a SQR program on Unix Platform with Oracle RDBMS. It's an interfacing program to integrate data from foreign sites to PeopleSoft database, using a flat file input. After many hours of processing, the program stops with a coredump error (memory fault). With top command we noticed... (1 Reply)
Discussion started by: araziki
1 Replies

2. Programming

Memory fault(coredump)

Dear All, I made a program which do some simple jobs like reading data from other process's shared memory and writing messages to the queues of other process. what happens is my program works fine and do all the task as expected but then then program ends it give Memory fault(coredump). I... (0 Replies)
Discussion started by: ralo
0 Replies

3. Shell Programming and Scripting

Awk:Segementation Fault

I am using awk command to sort a large file (7MB) and compare two files of 7 MB. The code is working fine for smaller files. But it gives following error for larger files Segmentation fault (core dumped) I am doing this on cygwin Please help in this regard Thanks Sandeep (1 Reply)
Discussion started by: sandeep_hi
1 Replies

4. Programming

Passed the compiler,but segementation fault

To find a number if it is a prime number, I cannot find any wrong. #include <stdio.h> #include <stdlib.h> int isPrime(int valToCheck) { int i; int retVal = 1; for(i=1;i<valToCheck;i++) { if(valToCheck%i == 0 && i != 1) { retVal = 0; ... (1 Reply)
Discussion started by: zhshqzyc
1 Replies

5. AIX

Segmentation fault(coredump)

Hi All Can anybody help me? When ever am trying to run topas system gives me an error Segmentation fault(coredump) does anybody ahve solution for this? (4 Replies)
Discussion started by: vjm
4 Replies

6. Ubuntu

Memory fault(coredump)

Hey guys, I am new to the Linux world and have a question to post. When I ssh from a HP-UX machine to a ubuntu machine I get the following error message Memory fault(coredump) i.e. ssh 192.168.1.3 I get this message as shown below Memory fault(coredump) Can someone please explain... (2 Replies)
Discussion started by: fkaba81
2 Replies

7. Solaris

memory fault (coredump)

Getting memory fault (coredump) and segmentation fault(coredump) when i tried javac or java -version. what could be the problem? Regards Eswar (2 Replies)
Discussion started by: BhuvanEswar
2 Replies

8. Shell Programming and Scripting

Segmentation Fault(coredump)

I'm getting this error when trying to run a Acucobol program thru UNIX.. Segmentation Fault(coredump) Precompiler error prevents compilation of xxxxxx.co. Please help me in this case.. (1 Reply)
Discussion started by: Manish4
1 Replies

9. Homework & Coursework Questions

Memory fault(coredump)

I am writing a program that copies a program and prints the program with a line count. this is the program I wrote: #include <stdio.h> main() { int c; int nl_cnt = 0; while((c = getchar()) != EOF){ if(c = '\n'){ nl_cnt++;... (3 Replies)
Discussion started by: heywoodfloyd
3 Replies

10. UNIX for Advanced & Expert Users

Memory fault(Coredump)

Hi, In my application we have one job which is used to process the files. But that job is failing with memory fault while processing a file or while shutting down the job. Sometime it generates the coredump and sometimes not. When I analysed the core dump I got below code snippet where it... (3 Replies)
Discussion started by: shilpa_20
3 Replies
explain_fputs(3)					     Library Functions Manual						  explain_fputs(3)

NAME
explain_fputs - explain fputs(3) errors SYNOPSIS
#include <libexplain/fputs.h> const char *explain_fputs(const char *s, FILE *fp); const char *explain_errno_fputs(int errnum, const char *s, FILE *fp); void explain_message_fputs(char *message, int message_size, const char *s, FILE *fp); void explain_message_errno_fputs(char *message, int message_size, int errnum, const char *s, FILE *fp); DESCRIPTION
These functions may be used to obtain explanations for errors returned by the fputs(3) system call. explain_fputs const char *explain_fputs(const char *s, FILE *fp); The explain_fputs function is used to obtain an explanation of an error returned by the fputs(3) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. The errno global variable will be used to obtain the error value to be decoded. s The original s, exactly as passed to the fputs(3) system call. fp The original fp, exactly as passed to the fputs(3) system call. Returns: The message explaining the error. This message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. This will be overwritten by the next call to any libexplain function which shares this buffer, including other threads. Note: This function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. Example: This function is intended to be used in a fashion similar to the following example: if (fputs(s, fp) < 0) { fprintf(stderr, "%s ", explain_fputs(s, fp)); exit(EXIT_FAILURE); } The above code example is available pre-packaged as the explain_fputs_or_die(3) function. explain_errno_fputs const char *explain_errno_fputs(int errnum, const char *s, FILE *fp); The explain_errno_fputs function is used to obtain an explanation of an error returned by the fputs(3) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. errnum The error value to be decoded, usually obtained from the errno global variable just before this function is called. This is neces- sary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value of errno. s The original s, exactly as passed to the fputs(3) system call. fp The original fp, exactly as passed to the fputs(3) system call. Returns: The message explaining the error. This message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. This will be overwritten by the next call to any libexplain function which shares this buffer, including other threads. Note: This function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. Example: This function is intended to be used in a fashion similar to the following example: if (fputs(s, fp) < 0) { int err = errno; fprintf(stderr, "%s ", explain_errno_fputs(err, s, fp)); exit(EXIT_FAILURE); } The above code example is available pre-packaged as the explain_fputs_or_die(3) function. explain_message_fputs void explain_message_fputs(char *message, int message_size, const char *s, FILE *fp); The explain_message_fputs function is used to obtain an explanation of an error returned by the fputs(3) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. The errno global variable will be used to obtain the error value to be decoded. message The location in which to store the returned message. If a suitable message return buffer is supplied, this function is thread safe. message_size The size in bytes of the location in which to store the returned message. s The original s, exactly as passed to the fputs(3) system call. fp The original fp, exactly as passed to the fputs(3) system call. Example: This function is intended to be used in a fashion similar to the following example: if (fputs(s, fp) < 0) { char message[3000]; explain_message_fputs(message, sizeof(message), s, fp); fprintf(stderr, "%s ", message); exit(EXIT_FAILURE); } The above code example is available pre-packaged as the explain_fputs_or_die(3) function. explain_message_errno_fputs void explain_message_errno_fputs(char *message, int message_size, int errnum, const char *s, FILE *fp); The explain_message_errno_fputs function is used to obtain an explanation of an error returned by the fputs(3) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. message The location in which to store the returned message. If a suitable message return buffer is supplied, this function is thread safe. message_size The size in bytes of the location in which to store the returned message. errnum The error value to be decoded, usually obtained from the errno global variable just before this function is called. This is neces- sary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value of errno. s The original s, exactly as passed to the fputs(3) system call. fp The original fp, exactly as passed to the fputs(3) system call. Example: This function is intended to be used in a fashion similar to the following example: if (fputs(s, fp) < 0) { int err = errno; char message[3000]; explain_message_errno_fputs(message, sizeof(message), err, s, fp); fprintf(stderr, "%s ", message); exit(EXIT_FAILURE); } The above code example is available pre-packaged as the explain_fputs_or_die(3) function. SEE ALSO
fputs(3) write a string to a stream explain_fputs_or_die(3) write a string to a stream and report errors COPYRIGHT
libexplain version 0.52 Copyright (C) 2009 Peter Miller explain_fputs(3)
All times are GMT -4. The time now is 02:12 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy