LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 10-18-2005, 01:26 AM   #1
kranti
LQ Newbie
 
Registered: Oct 2005
Location: Pune
Posts: 17

Rep: Reputation: 0
allocation problem [static stack storage]


I've written a UDP client server multithreaded application in C in which I've declared one global char array which is a 2 dimensional array of size 10 by 256.
I'm processing this array in a function in which i'm opening one log file. This file gets opened successfully for 8 out of 10 times. If i increase the size from 10 to 50 the failure occures at 48th position. When i try to debug, the string (char array) containing the file path gets corrupted at the mentioned positions as the flow goes on & hence the file doesn't get opened.

Why does the file path get lost? Can there be any problem with respect to stack or heap storage?
 
Old 10-18-2005, 09:10 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
You are overwriting your storage.
stack grows downward (toward larger addresses).
Code:
char tmp[32]={0x0};
int j=0;
memset(tmp,' ',34);
the memset call puts too many characters into tmp. The extra characters will end up in the "j" variable's memory space, depending on alignment.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Difference b/t Kernel stack and User stack hazzyb Linux - Software 2 09-29-2008 07:40 PM
stack problem C eagle683 Programming 3 05-17-2005 04:52 PM
C programming: memory allocation / pointer problem I think sterrenkijker Programming 2 04-17-2005 03:07 AM
Memory Allocation Problem? lanky666 Linux - Software 3 02-14-2004 06:27 PM
Partition size allocation problem Supraj Linux - Newbie 3 08-08-2001 02:36 AM

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

All times are GMT -5. The time now is 11:45 PM.

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