LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 04-15-2023, 02:56 PM   #1
AlinaC
LQ Newbie
 
Registered: Nov 2022
Posts: 8

Rep: Reputation: 0
Simulating simple mail server with C++ using AVL tree: Abnormal program termination


I've written a program that simulates a simple mail server. All good while testing on my local computer. But program fails when I upload it to the testing environment and displays the following error: "Abnormal program termination (Segmentation fault/Bus error/Memory limit exceeded/Stack limit exceeded)". I'm using AVL tree and have re-written program twice, first using recursion and after -iterative search and insertion. But both ended up with the same issue (

Can you please have a look and share your ideas where the issue can be? Will appreciate your feedback.
<code removed>

Update: thank you for your comments. I understand now that it was hard to expect specific advices as I was not able to upload the whole program with test data (was too long for here). Also it was important to mention that there were some limitations set (as this was a training task in making deep/shallow copies). Will keep this as a lessons learnt for future.

For those who are interested in the outcome: the issues were with nullptrs and not checking boundaries. Simple debug went well but when I started testing edge cases, found the root causes for errors.

Last edited by AlinaC; 04-17-2023 at 02:00 PM.
 
Old 04-15-2023, 04:52 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Asking others to build, test and debug your complete program without even saying under what conditions it fails is asking a little bit much.

Telling us that you have rewritten the program twice is also not useful to others understanding of your problem. Why did you rewrite it rather than troubleshoot it?

Telling us what you have done to troubleshoot and isolate the problem would be more helpful.

Please review the Site FAQ for guidance in asking well formed questions. Especially visit the link from that page, How to Ask Questions the Smart Way for discussion of things to consider when asking others for help.
 
Old 04-15-2023, 05:06 PM   #3
AlinaC
LQ Newbie
 
Registered: Nov 2022
Posts: 8

Original Poster
Rep: Reputation: 0
May be I was not clear enough, sorry about that. BUT

Quote:
Originally Posted by astrogeek View Post
Asking others to build, test and debug your complete program without even saying under what conditions it fails is asking a little bit much.
I don't ask to debug - as I have written that on a local computer there are no errors, all works fine.

The problem appears when loading code into the testing environment. And yes, I have no idea under what conditions this error happens because this Abnormal termination error message is the only feedback I get ((.

Quote:
Telling us that you have rewritten the program twice is also not useful to others understanding of your problem. Why did you rewrite it rather than troubleshoot it?
I have re written it in order to move from recursion to iterative search and insertion, to optimize memory use. But it resulted in the same error message.

The goal of this post was to get feedback, if possible, about any wrong use one might see there. Or eg advice on optimizing performance of AVL search/insertion
 
Old 04-15-2023, 08:22 PM   #4
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,225

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Uhm, am I missing something? All the program does is allocate three arrays on the stack.

If everything you're saying is true and you've posted all you need to, then either there's something wrong with the "testing environment's" RAM, or there's something very important about it that you're not telling us (e.g. that it's some sort of retro computer or other memory-constrained environment).

If that is not the case and you've simply omitted information, then build the program with debugging symbols, and run gdb or lldb on it when it's in the testing environment. The backtrace will tell you where the infinite recursion is (if it is that).

Also, don't forget to check the "testing environment's system logs. Such as "dmesg", if it's Linux. I mean, maybe the OOM-killer killed it.

Last edited by dugan; 04-15-2023 at 08:35 PM.
 
2 members found this post helpful.
Old 04-16-2023, 06:37 AM   #5
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
The program in post #1 works faultlessly for me (after removing some preprocessor-lines). Though it doesn't actually do anything.

Edit: valgrind(1) can point out the bugs in the code. Here is a simple correction:
Code:
--- alinac.cc0  2023-04-16 13:44:47.291267538 +0200
+++ alinac.cc   2023-04-16 13:55:38.159683847 +0200
@@ -318,10 +318,11 @@
     // New node creation
     Node *newNode(const CString& key) {
       Node *node = new Node(key);
       node->left = nullptr;
       node->right = nullptr;
+      node->parent = nullptr;
       node->height = 1;
       return (node);
     }

Last edited by NevemTeve; 04-16-2023 at 06:58 AM.
 
Old 04-16-2023, 06:55 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
that may mean an incompatible library (.so file) or something else. But anyway I would try to use valgrind on your code.
 
Old 04-16-2023, 01:12 PM   #7
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Though I think newNode should be dropped, insted the Node constructor(s) should initialize every field.
 
Old 04-17-2023, 10:49 AM   #8
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
Does this error code mean: "Segmentation fault or Bus error or Memory limit exceeded or Stack limit exceeded" ??

What is the error code? Please post exactly what you get on your console when you try it.

Why are you implementing an AVL tree when there are already existing container classes (I believe, even in the standard libraries) which are known to implement them correctly? "Writing data structure implementations by hand" are things we're only forced to do at University. Over at "github.com," my search produced 716 results.

Last edited by sundialsvcs; 04-17-2023 at 04:57 PM.
 
Old 04-17-2023, 11:38 AM   #9
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
(Sounds like some kind of contest or exam task.)
 
Old 04-17-2023, 04:58 PM   #10
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
@NevemTeve: I'm not so sure.

My guess is that there's actually a bug in this person's implementation, possibly caused by the freeing of memory resources, which is not apparent on the development machine with its probably-bottomless resources. The ulimit command can sometimes be used to cause these bugs to appear on a "dev box," but I've had somewhat mixed success with it.

Nevertheless – if there is any sort of "complicated data structure" which someone else(!) has already encapsulated in a trustworthy "container class," my strong recommendation to any C++ programmer is: "use the container class." Don't look inside of it: "you frankly don't care how the damn thing works, as long as you know that it does." In addition to what you know to be supplied by the "standard libraries" of your chosen compiler, GitHub and SourceForge are usually good sources of stuff that "somebody else has already debugged."

Quote:
"Actum Ne Agas: "Do Not Do A Thing Already Done.™"
The reason why you are writing this program is to mock the behavior of a mail server – not to correctly (re-)implement "an AVL tree."

(P.S.: I presume that you did your online research at the places aforementioned, to see if somebody else(!!) has not already implemented a "mock mail server?" ... Just askin' ... Whups, my GitHub query just listed 33 results, not all of them applicable.)

Last edited by sundialsvcs; 04-17-2023 at 05:12 PM.
 
Old 04-17-2023, 05:09 PM   #11
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,225

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Quote:
Originally Posted by sundialsvcs View Post
Nevertheless – if there is any sort of "complicated data structure" which someone has already encapsulated in a trustworthy "container class," my strong recommendation to any C++ programmer is: "use the container class."
That would be std::set and std::map, both of which are implemented as red-black trees.
 
Old 04-17-2023, 11:29 PM   #12
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Also seems like Original Poster has lost interest in the topic.
Off: I have a Balanced Binary Tree (BaBiT) implementation written in C which is freely available. (No direct link here, can be found on sourceforge.net)

Last edited by NevemTeve; 04-18-2023 at 04:38 PM.
 
Old 04-18-2023, 04:01 PM   #13
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
@NevemTeve: I certainly wouldn't consider it to be "advertising," and I'd encourage you to edit your post to include the link. But it sounds like an excellent thing to contribute to GitHub ... where it would most easily be found.
 
1 members found this post helpful.
  


Reply

Tags
c programming, c++ programming



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
AVL Tree Insertion - Implementation mitchell7man Programming 2 12-13-2013 03:43 AM
AVL tree vishalbutte Programming 1 03-12-2006 07:45 AM
Insert recursive method in an AVL trees. HOW???? carspidey Programming 1 03-08-2006 07:13 PM
Question about abnormal program termination ghoughto Programming 5 06-15-2005 07:04 AM
Clearing Resource Lock After Abnormal Termination CooManChu Linux - General 3 01-22-2005 11:04 AM

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

All times are GMT -5. The time now is 04:40 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