hi guys,
i have a weird problem with printf statement. I have a function which
just prints a string literal. In my program this function will be
called > 2000 times. I get a segmentation fault after the function
has been called for ~ 1700 times.
But if i remove printf statement and just put any assignment
expression or any other expression, it works fine. Even if i put
fwrite(), it works fine.
Has std I/O got anything to do with stack overflow ?
void compute_stream_table(Addr data_addr)
{
printf("into function\n");
/* ................... */
}
Any ideas why it is happening ?
Thanks. 7 10479
Adi wrote: hi guys,
i have a weird problem with printf statement. I have a function which just prints a string literal. In my program this function will be called > 2000 times. I get a segmentation fault after the function has been called for ~ 1700 times.
But if i remove printf statement and just put any assignment expression or any other expression, it works fine. Even if i put fwrite(), it works fine. Has std I/O got anything to do with stack overflow ?
void compute_stream_table(Addr data_addr) { printf("into function\n");
/* ................... */ }
Any ideas why it is happening ?
Something in the `/* ................... */' is wrong,
or something in the code that calls compute_stream_table()
is wrong. Hope this helps.
(In other words, there's no obvious reason why this
printf() should cause any trouble. Try chopping your
program down to the shortest, complete and compilable
version that demonstrates the problem, and post that
reduced code.)
-- Er*********@sun.com
Adi <pu********@yahoo.com> wrote: i have a weird problem with printf statement. I have a function which just prints a string literal. In my program this function will be called > 2000 times. I get a segmentation fault after the function has been called for ~ 1700 times.
But if i remove printf statement and just put any assignment expression or any other expression, it works fine. Even if i put fwrite(), it works fine. Has std I/O got anything to do with stack overflow ?
That is a typical sign of memory corruption happening in your program,
i.e. you're using memory you didn't allocate, e.g. by writing outside
of memory areas you allocated. printf() itself allocates memory and
when there's memory corruption going on the call of malloc() or free()
it does may lead to the segmentation fault. You can be rather sure it
got nothing to do with printf() by itself, which just triggers a bug
lurking somewhere else in your program.
Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@physik.fu-berlin.de
\__________________________ http://www.toerring.de
Thanks Jens and Eric, for your input... The code which i have is a
very big one spanning across many files(around 20), which i cannot
afford to debug (and added to that it's not the code written by me). I
have put fwrite() instead of relying on printf and fprintf (which give
me seg fault), which works fine and solves my purpose.
Now, i have a question - doesnt fwrite() allocate memory for itself
like printf or fprintf() ?
Thanks. Je***********@physik.fu-berlin.de wrote in message news:<c1*************@uni-berlin.de>... Adi <pu********@yahoo.com> wrote: i have a weird problem with printf statement. I have a function which just prints a string literal. In my program this function will be called > 2000 times. I get a segmentation fault after the function has been called for ~ 1700 times.
But if i remove printf statement and just put any assignment expression or any other expression, it works fine. Even if i put fwrite(), it works fine. Has std I/O got anything to do with stack overflow ?
That is a typical sign of memory corruption happening in your program, i.e. you're using memory you didn't allocate, e.g. by writing outside of memory areas you allocated. printf() itself allocates memory and when there's memory corruption going on the call of malloc() or free() it does may lead to the segmentation fault. You can be rather sure it got nothing to do with printf() by itself, which just triggers a bug lurking somewhere else in your program.
Regards, Jens
On 2 Mar 2004 14:56:30 -0800, pu********@yahoo.com (Adi) wrote: Thanks Jens and Eric, for your input... The code which i have is a very big one spanning across many files(around 20), which i cannot afford to debug (and added to that it's not the code written by me). I have put fwrite() instead of relying on printf and fprintf (which give me seg fault), which works fine and solves my purpose.
I'm afraid you may be fooling yourself. Quite likely you have
temporarily hidden the error, and it will bite you unexpectedly.
If this program is to be used by anyone else, you can't afford *not*
to debug the original problem.
--
Al Balmer
Balmer Consulting re************************@att.net al******@att.net wrote... On 2 Mar 2004 14:56:30 -0800, pu********@yahoo.com (Adi) wrote:
Thanks Jens and Eric, for your input... The code which i have is a very big one spanning across many files(around 20), which i cannot afford to debug (and added to that it's not the code written by me). I have put fwrite() instead of relying on printf and fprintf (which give me seg fault), which works fine and solves my purpose.
I'm afraid you may be fooling yourself. Quite likely you have temporarily hidden the error, and it will bite you unexpectedly.
If this program is to be used by anyone else, you can't afford *not* to debug the original problem.
Heed that advice, OP!
--
"Premature optimization is the root of all evil." - Donald Knuth pu********@yahoo.com (Adi) wrote in message news:<c8**************************@posting.google. com>... hi guys,
i have a weird problem with printf statement. I have a function which just prints a string literal. In my program this function will be called > 2000 times. I get a segmentation fault after the function has been called for ~ 1700 times.
I'm quite confident it's not printf, I have a test file which has
exactly 1 million lines of text and printf just chugs along without
any noise. I suspect something wrong with the programs management of
memory, (OT) if you happen to use linux you might wanna try out
valgrind to inspect your program, hope this helps.
On 2 Mar 2004 14:56:30 -0800, pu********@yahoo.com (Adi) wrote: Thanks Jens and Eric, for your input... The code which i have is a very big one spanning across many files(around 20), which i cannot afford to debug (and added to that it's not the code written by me). I have put fwrite() instead of relying on printf and fprintf (which give me seg fault), which works fine and solves my purpose.
Now, i have a question - doesnt fwrite() allocate memory for itself like printf or fprintf() ?
In what way do you think any of these functions allocate memory?
<<Remove the del for email>> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Anks |
last post by:
i am unable to find why following code is giving segmentation
fault.... way to produce seg fault: run the program... give input
12345678....enter any key except 'x'.... again give 12345678 as...
|
by: damian birchler |
last post by:
If I run the following I get a segmentation fault:
#define NAMELEN 15
#define NPERS 10
typedef struct pers {
char name;
int money;
} pers_t;
|
by: Zheng Da |
last post by:
Program received signal SIGSEGV, Segmentation fault.
0x40093343 in _int_malloc () from /lib/tls/libc.so.6
(gdb) bt
#0 0x40093343 in _int_malloc () from /lib/tls/libc.so.6
#1 0x40094c54 in malloc...
|
by: Fra-it |
last post by:
Hi everybody,
I'm trying to make the following code running properly, but I can't get
rid of the "SEGMENTATION FAULT" error message when executing.
Reading some messages posted earlier, I...
|
by: Paminu |
last post by:
I have a wierd problem.
In my main function I print "test" as the first thing. But if I run the call
to node_alloc AFTER the printf call I get a segmentation fault and test is
not printed!
...
|
by: DanielJohnson |
last post by:
int main()
{
printf("\n Hello World");
main;
return 0;
}
This program terminate just after one loop while the second program
goes on infinitely untill segmentation fault (core dumped) on...
|
by: Andrea |
last post by:
I wrote this code:
void * xmalloc (size_t size){
register void *value = OPENSSL_malloc(size);
if (value == 0)
printf("virtual memory exhausted");
return value;
}
int _chooseTSK(char*...
|
by: ollii |
last post by:
Hello evryboody, i created client and srever program that they can both communicate together by TCP and UDP, but when i want to send message to server from client i get error on the server i get...
|
by: aarklon |
last post by:
char *f()
{
char *s = malloc(8);
strcpy(s,"good bye");
}
int main(void)
{
printf("\n %s",*f()='A');
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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...
|
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...
|
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...
| |