473,378 Members | 1,688 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

*** stack smashing detected *** How to identify the corresponding line of code

Hello all!

I am sorry my first post here is a question. I hope to contribute during the posting and replies on this thread.

I am stuck for 1 week in a *** stack smashing detected *** bug in my C program running in a i386 desktop with Ubuntu 7.0.4.
I would have pasted the code here but its approx 2000 lines. It has a dozen of functions and a main program. gdb backtrace reports the error ocurred at the instruction that return from the main program, hence, curiously all the outputs from the program are done successfully but the program does not end normally as it abnormally terimnate with this bug (!!).

I tryed to detect the line in the source code where I could be smashing the stack with valgrind, but I arrived to the conclusion that it canīt help me to debug my current stack smashing error (Reference: Go to the page below on wikipedia, and make a "search in this page" for the "stack smashing"

http://en.wikipedia.org/wiki/Valgrind

I am currently carefully checking each line of code, one by one, trying to find out the buggy statement. Meanwhile I would appreciate if someone could:

1- Point out any tool that may help me to pinpoint where (I mean, in which statement) I am doing this stack smashing?
2- Give me some clues that could help me speeding up the buggy statement identification in the code.
Aug 16 '07 #1
5 56135
Banfa
9,065 Expert Mod 8TB
This sort of error is usually the result of writing to the location pointed to by an uninitialised pointer or writting off the end of an array (buffer overrun).

It is also one of the hardest types of bug to find.

1. Check all your pointers and arrays.

2. If possible try chopping out chunks of code (starting from the end of the program) until the program starts working without error (although obviously the output may not be correct). There is then a good chance that the bug is in the last bit of code you chopped out.
Aug 16 '07 #2
Problem Solved!
Thank you Banfa, for your valuable contribution.
The buffer overrun occurred because I was passing a parameter longer than 10 characters to the program. This parameter is the name of the file I should read as input. I have defined a string variable of length 10 to store and manipulate this name.

Now I will tell you the story about the debugging as it may help someone with the same problem in the future.

I got an input file with parameters which never leaded to error. I started changing one by one the parameters in the file to make it little by little equal to the one from which I always got the error. At the end both input files were equal and only one leaded to the error. After some minutes of astonishment ... I changed the NAME of the "bad" input file and it run OK. Finally, a quick check in the statements that referenced the name of the input file got me to the overrunning statement!
Aug 17 '07 #3
Problem Solved!
The buffer overrun occurred because I was passing a parameter longer than 10 characters to the program. This parameter is the name of the file I should read as input. I have defined a string variable of length 10 to store and manipulate this name.

I'm still new at all of this, but isn't there a new type of string, using #include <string> (no .h) that calculates the amount of space needed, or am I totally on the wrong subject here ?



By the way, Great job both you and Banfa, I'm glad everything worked out well.
Aug 17 '07 #4
Banfa
9,065 Expert Mod 8TB
I'm still new at all of this, but isn't there a new type of string, using #include <string> (no .h) that calculates the amount of space needed, or am I totally on the wrong subject here ?
That rather depends on whether the project is written in C or C++.

There is a string type defined in string (no .h) but it is a class and thus only available in C++. There is also the odd occasion (not very often though) when a character array is more desirable than the string class.
Aug 17 '07 #5
That rather depends on whether the project is written in C or C++.

There is a string type defined in string (no .h) but it is a class and thus only available in C++. There is also the odd occasion (not very often though) when a character array is more desirable than the string class.

Oh I see, thanks for clearing that up for me.
Aug 17 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Willie Walker | last post by:
Hi: I'm working on Orca, a screen reader for the GNOME platform, and it's being done in Python. Python is working really for us right now and I'm quite happy with many aspects of it. Is...
2
by: Fred Armitage | last post by:
I have a fairly complex application written using a vb code-behind dll. However, I'd like to write one particular aspx page utilising in-line code so that it can easily be modified as needed by the...
1
by: redhair | last post by:
In a asp.net page (.aspx) below, I'd like to know the in-line code ("<%Output()%> ) will be executed in which page process lifecycle? thanks. <Script Language="VB" Runat="Server"> Sub...
1
by: R | last post by:
Hi All, I'm using PHP 5, my code fully separates code from content, my code throws exceptions (LIZException) when error occurs. but every time I throw exception I get this fatal error: ...
0
by: Jon Paal | last post by:
what would be the command line code to add an image as a resource to a dll ?
4
by: TS | last post by:
I have an application on one server that shows line numbers in stack trace, but on another server the "in c:\xxx.aspx:line 9999" part that accompanies the "at" part doesn't show. Besides this...
5
by: nothingfights | last post by:
# include <iostream> using namespace std; int main() { char k; for(int i=0; i<127; i++) { cout << ((char) i); k= (i+1)%16;
1
by: rahullko05 | last post by:
one line code to replace an image without page refresh
1
by: rahullko05 | last post by:
Can anybody help me? to write one line code to render html inside a div element. Thanks.
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.