Angband.oook.cz
Angband.oook.cz
AboutVariantsLadderForumCompetitionComicScreenshotsFunniesLinks

Go Back   Angband Forums > Angband > Development

Reply
 
Thread Tools Display Modes
Old April 14, 2021, 01:31   #51
will_asher
DaJAngband Maintainer
 
will_asher's Avatar
 
Join Date: Apr 2007
Location: San Antonio, TX
Posts: 1,007
Donated: $10
will_asher is on a distinguished road
How do I know if it's writing beyond the boundaries of an array?
and How do I know what the boundaries are?

When I first started making DaJAngband, I just discovered the txt files in the lib folder (the subfolder was called something other than gamedata at that point), and changed some things and added some new monsters. I posted about making changes in the txt files on here, and someone suggested I make my own variant. I said I can't do that I know only the barest basics of C, but they said something to the effect of Oh it isn't hard, you can probably figure a lot of things out by the comments. So I looked at the code, and the comments were so thorough in saying what the code was doing, that I could figure out how to customize a lot of stuff in the code. I'm a meddler, not a programmer, but I made my own variant before. I can do it again (with the help of the nice people here).
__________________
Will_Asher
aka LibraryAdventurer

My old variant DaJAngband:
http://sites.google.com/site/dajangbandwebsite/home (defunct and so old it's forked from Angband 3.1.0 -I think- but it's probably playable...)
will_asher is offline   Reply With Quote
Old April 14, 2021, 05:21   #52
backwardsEric
Adept
 
Join Date: Aug 2019
Posts: 136
backwardsEric is on a distinguished road
Quote:
Originally Posted by will_asher View Post
How do I know if it's writing beyond the boundaries of an array?
and How do I know what the boundaries are?
There's tools to help detect them. I don't know what's best or readily available for your environment (Windows + Visual Studio). Electric Fence, https://en.wikipedia.org/wiki/Electric_Fence , is one fairly generic one for C. Like many of those tools, it's likely best used in conjunction with a source debugger that will let you set breakpoints and query the call stack and contents of memory.

As for the second question, the boundaries are set when the memory allocation happened - with the size that was passed to the allocator.

Besides finding a tool to help detect the source of the memory corruption, manually reviewing your changes, while time-consuming, will likely help. Did the parts you added to the player structure involve dynamic allocation (likely if they are pointers)? If so, check that the size specified for allocation is the right one. Try to identify the lifetime of what was allocated - when is it allocated and when is it released. Are there attempts to access it after it is released (either for reading, writing, or to release it again)? If so, that would be a problem. If you didn't add anything that required dynamic allocation, you would want to check your changes to the savefile loading. Are the loads of the right size and not overflowing the destination memory?
backwardsEric is offline   Reply With Quote
Old April 14, 2021, 16:26   #53
will_asher
DaJAngband Maintainer
 
will_asher's Avatar
 
Join Date: Apr 2007
Location: San Antonio, TX
Posts: 1,007
Donated: $10
will_asher is on a distinguished road
here's what I did. I added some things to the player struct in player.h like so

"
s16b p_luck; /* Luck */
s16b slimed; /* slime level */
<a few more similar ones, all of them are s16bs>
"
then I added them to save.c and load.c like so
"
wr_s16b(player->p_luck); /* luck */
wr_s16b(player->slimed); /* slime */
...
"
"
rd_s16b(&player->p_luck);
rd_s16b(&player->slimed);
...
"

oh and save.c had this "
wr_s16b(0);
wr_s16b(0);
wr_s16b(0);
wr_byte(0);
"
in that spot before with a corresponding
"
strip_bytes(7);
"
in load.c.
I figured I didn't need that stuff and cut it out.
hmmm...
So just now I put those empty s16bs and the strip_bytes() line back in and ...it didn't make any difference. thought it was worth a try.

Anyway, that's all I did to the savefiles.
EDIT: and I don't know what "dynamic allocation" is. I didn't change anything that looked like it allocated or released anything.
__________________
Will_Asher
aka LibraryAdventurer

My old variant DaJAngband:
http://sites.google.com/site/dajangbandwebsite/home (defunct and so old it's forked from Angband 3.1.0 -I think- but it's probably playable...)

Last edited by will_asher; April 14, 2021 at 16:33.
will_asher is offline   Reply With Quote
Old April 14, 2021, 22:07   #54
Nick
Vanilla maintainer
 
Nick's Avatar
 
Join Date: Apr 2007
Location: Canberra, Australia
Age: 55
Posts: 8,760
Donated: $60
Nick will become famous soon enough
Quote:
Originally Posted by will_asher View Post
here's what I did.
That doesn't look like it would lead to memory issues in itself, but after the change it probably wouldn't load old savefiles correctly, which could conceivably have led to your problems. Have you tried with a fresh savefile?
__________________
One for the Dark Lord on his dark throne
In the Land of Mordor where the Shadows lie.
Nick is offline   Reply With Quote
Old April 14, 2021, 23:50   #55
will_asher
DaJAngband Maintainer
 
will_asher's Avatar
 
Join Date: Apr 2007
Location: San Antonio, TX
Posts: 1,007
Donated: $10
will_asher is on a distinguished road
Quote:
Originally Posted by Nick View Post
That doesn't look like it would lead to memory issues in itself, but after the change it probably wouldn't load old savefiles correctly, which could conceivably have led to your problems. Have you tried with a fresh savefile?
yes

(Adding a little blah blah because the forum won't let me post a 3-character reply.)
__________________
Will_Asher
aka LibraryAdventurer

My old variant DaJAngband:
http://sites.google.com/site/dajangbandwebsite/home (defunct and so old it's forked from Angband 3.1.0 -I think- but it's probably playable...)
will_asher is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
can we make identify more common ? Sky Vanilla 16 September 10, 2017 10:20
Make Artistry automatic bagori nd Sil 4 September 26, 2016 18:22
How many variant developers/maintainers have beaten their own variant? Delver Variants 12 June 5, 2009 09:08
Variant writing.. quickstart guide? Also, Hengband variant suggestions? dzhang Variants 34 April 1, 2009 00:45
Trying to make my own variant bpleshek Variants 8 September 15, 2008 20:42


All times are GMT +1. The time now is 13:39.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.