Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 08-01-2005, 06:58 AM   #1 (permalink)
melo_1981
newbie ;-)
 
Join Date: Aug 2005
Posts: 3
melo_1981 is on a distinguished road
Send a message via AIM to melo_1981
ASSERT question *excuse my newbie-ness*

hello:

i would like to write a global function that will validate pointers (based on a range of addresses) for newly added code. Several other functions will call this global function, and if the value is bad, i want to do an assert.

what would the code (psuedo-code) look like for this?

thanks for any and all help.
melo_1981 is offline   Reply With Quote
Old 08-02-2005, 12:15 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,720
redhead is on a distinguished road
Give me some time, and I'll get back to this one.. Just havn't come up with a simple example yet..
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 08-02-2005, 03:38 AM   #3 (permalink)
melo_1981
newbie ;-)
 
Join Date: Aug 2005
Posts: 3
melo_1981 is on a distinguished road
Send a message via AIM to melo_1981
Quote:
Originally Posted by redhead
Give me some time, and I'll get back to this one.. Just havn't come up with a simple example yet..

a global function that will validate pointers (based on a range [m,n] of memory addresses) for newly added code. Several other functions will call this global function, and if the value is bad, i want to do an assert.

so something like:

void myAssert( pointerType p1)
{

// check for valid memory address
if ( (p1 < m) || (p1 > n ) )
assert1(true); // do an assert if pointer is not in valid range
else
assert1(false);
}

i get all confused with * and & when it has to do with memory addresses, but that's basically the jist of it.
melo_1981 is offline   Reply With Quote
Old 08-02-2005, 06:15 AM   #4 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,720
redhead is on a distinguished road
How do you verify the address is correct ?? do you have some sort of strickt instruction loading routine of your own, or what ??
Let me repeat myself, how do you verify the address is correct ??
Uppon execution you normaly wouldn't know where in the memory space your jump/branch instructions will be placed, they are just added to the runtime heap, which you dont even know where will start at, this can only be controled if you're working in an envirenment, where you yourself have written the loading routine..
Or perhaps you want to check if the memory allocated in a struct/class is allocated within the structs memory range.. then again this can't be verified, since the memory allocation normaly asserts a jump or pointer instruction to where the remainder of hte memory allocated will be available at..
I'm confused.....

If at some point I do get what you're looking for here, I will come up with a way to achieve it, but so far that looks to be some nasty pointer arithmetik.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 08-02-2005, 07:52 AM   #5 (permalink)
melo_1981
newbie ;-)
 
Join Date: Aug 2005
Posts: 3
melo_1981 is on a distinguished road
Send a message via AIM to melo_1981
i am given a dedicated range of valid addresses (hardware). i want the function to take the pointer, validate the adress is in the specified range (if it is not, then do an assert).

sorry if i'm not clear...
melo_1981 is offline   Reply With Quote
Old 08-02-2005, 12:05 PM   #6 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,720
redhead is on a distinguished road
hmmm.. I'm still not clear if I'm getting this..
And I could be way off.. But wouldn't something like this work ??
Code:
#define MIN 0xfe343468
#define MAX 0xfff23435
#define ASSERT(p) (assert((MIN >= &(p) && &(p) <= MAX ));)
// blah blah, my code..
ASSERT(hardware_access)
Or are you working in some kernel-space, where you use mmap() with /dev/kmem to make the needed memory available for your routine ??
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Reply

Bookmarks

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
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
DB Design Question Part II sde Program Design and Methods 10 09-02-2008 11:37 AM
Hello! Please forgive newbie question jimmyoctane PHP 4 09-13-2004 06:33 AM
Would you mind if there were small flash elements at code newbie? sde Lounge 10 05-29-2004 09:05 PM
Another newbie question. Odoggy5 PHP 26 09-03-2003 02:19 PM
Newbie question. p0etsou1 Standard C, C++ 9 06-24-2003 07:47 AM


All times are GMT -8. The time now is 01:18 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting