Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
parse description bug
Dec 15, 2017, 10:08 pm
By Remcon
Couple bugs
Dec 12, 2017, 5:42 pm
By Remcon
Bug in disarm( )
Nov 12, 2017, 6:54 pm
By GatewaySysop
Bug in will_fall( )
Oct 23, 2017, 1:35 am
By GatewaySysop
Bug in do_zap( ), do_brandish( )
Oct 18, 2017, 1:52 pm
By GatewaySysop
LOP 1.45
Author: Remcon
Submitted by: Remcon
LOP Heroes Edition
Author: Vladaar
Submitted by: Vladaar
Heroes sound extras
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.3
Author: Vladaar
Submitted by: Vladaar
Memwatch
Author: Johan Lindh
Submitted by: Vladaar
Users Online
CommonCrawl, Bing, Majestic-12, Yahoo!, Google

Members: 0
Guests: 19
Stats
Files
Topics
Posts
Members
Newest Member
477
3,706
19,240
608
LAntorcha
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » Codebases » SWFOTE FUSS » I'm a bit confused about obje...
Forum Rules | Mark all | Recent Posts

I'm a bit confused about object contents
< Newer Topic :: Older Topic >

Pages:<< prev 1 next >>
Post is unread #1 Dec 23, 2008, 9:26 pm
Go to the top of the page
Go to the bottom of the page

Keberus
Conjurer
GroupFUSS Project Team
Posts341
JoinedJun 4, 2005

Okay, someone was telling me they were having problems in their code, I eventually go to the point where it is looping the object contents by doing

 obj = obj->first_content 


Which I am accustomed to. When I started checking, I realized that obj->first_content, and obj->last_content are never set to NULL initially in FoteFuss, or SmaugFUSS, (and probably not SWRfuss). If they aren't NULLed out couldn't/wouldn't this mess up the linked list because thats how it would know if there was a first/last. So my main 2 questions are:

1) Do you/should you always intialize liked list first/last items to NULL before using.
2) If you are supposed to, why hasn't there been more problems before this relating to objects being corrupted/corrupting files or corrupt objects crashing the mud?

Thanks,
KeB
       
Post is unread #2 Dec 23, 2008, 9:37 pm
Go to the top of the page
Go to the bottom of the page

Quixadhal
Conjurer
GroupMembers
Posts398
JoinedMar 8, 2005

Keberus said:

1) Do you/should you always intialize liked list first/last items to NULL before using.
2) If you are supposed to, why hasn't there been more problems before this relating to objects being corrupted/corrupting files or corrupt objects crashing the mud?


Yes, in fact you *should* initialize EVERY variable in your entire codebase to a known value. One of the "features" of the C language is that only a very small set of variables get initialized by default (namely, static global variables).... in Ye Olde Days of 1MHz CPU's, this was great because it didn't "waste" CPU cycles on something that might not matter. It also means that as your project gets larger and larger, it's harder to debug. Setting every variable to a known value makes that debugging easier.

As to why it doesn't crash more often? Luck of the draw.

If your corrupt pointer (filled with random stuff) is written to before it's checked, you're fine. If it gets a value that is wrong, but happens to lie inside your address space -- strange things will happen, but it won't immediately cause a crash. Only if it falls outside your address space, does it generate a segmentation fault (meaning you accessed memory outside your segment set).
       
Post is unread #3 Dec 23, 2008, 10:16 pm
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,639
JoinedJan 1, 2002

The reason this hasn't become a problem with Smaug is because Smaug allocates nearly everything using the CREATE() macro, which is a fancy wrapper for calloc(). In C, calloc() initializes memory to zero as it's allocated. For pointers like obj->first_content, this effectively assigns NULL to them. Where you start to get trouble is if you change memory allocation schemes for some reason and don't realize you're no longer zeroing memory as it's allocated.
       
Post is unread #4 Dec 23, 2008, 10:41 pm
Go to the top of the page
Go to the bottom of the page

Keberus
Conjurer
GroupFUSS Project Team
Posts341
JoinedJun 4, 2005

Samson said:

The reason this hasn't become a problem with Smaug is because Smaug allocates nearly everything using the CREATE() macro, which is a fancy wrapper for calloc(). In C, calloc() initializes memory to zero as it's allocated. For pointers like obj->first_content, this effectively assigns NULL to them. Where you start to get trouble is if you change memory allocation schemes for some reason and don't realize you're no longer zeroing memory as it's allocated.


Ahh, I didn't know that about calloc(). Good to know, thanks for the info Samson.
       
Post is unread #5 Jan 20, 2009, 4:44 pm
Go to the top of the page
Go to the bottom of the page

Rojan QDel
Fledgling
GroupMembers
Posts25
JoinedDec 30, 2006

Yeah, I've found over time in the mass of sloppy code that is LotJ, that most things are NOT ever initialized. To protect from crashes, we essentially check every object variable for NULL/existence at all every time it is used. While this likely takes up unnecessary resources, it seems to be a good safe practice.
       
Post is unread #6 Jan 20, 2009, 6:53 pm
Go to the top of the page
Go to the bottom of the page

Remcon
Geomancer
GroupAdministrators
Posts1,866
JoinedJul 26, 2005

Shrug, typically I try to make sure everything gets set to a default as well as check for NULL data as I go. Both are good things to do (imho).
       
Post is unread #7 Jan 21, 2009, 10:08 pm
Go to the top of the page
Go to the bottom of the page

Rojan QDel
Fledgling
GroupMembers
Posts25
JoinedDec 30, 2006

I totally agree.
       
Post is unread #8 Jan 22, 2009, 10:52 am
Go to the top of the page
Go to the bottom of the page

David Haley
Sorcerer
GroupMembers
Posts903
JoinedJan 29, 2007

The usage of "unnecessary resources" is completely negligible in this case. There's no need at all to worry about making checks like this. Seriously: if people are writing MUDs in Python and other interpreted languages, do you really think a pointer equality test is going to hurt C/C++? :wink:
       
Post is unread #9 Jan 23, 2009, 9:50 pm
Go to the top of the page
Go to the bottom of the page

Rojan QDel
Fledgling
GroupMembers
Posts25
JoinedDec 30, 2006

In my experience, the only serious performance killer/CPU eater has been having a very quick succession of checks against a massive linked list. The biggest way I've noticed this is on LotJ in battles with a hundred or so ships, which seriously can lag the MUD because of the amount of ships in the game and the number of checks done during space combat for each ship/fire/etc.
       
Pages:<< prev 1 next >>