Thread: Check entered address range is valid

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    27

    Check entered address range is valid

    Hey

    I would like to know how to check whether a user specified start address and end address (for data locations) is valid or not

    Is there a way to check the given address is actually part of the program?

    I have malloc-ed to a variable, so would the correct method be to check whether the user inputted address is within that variable's scope?

    Thanks

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Err... why would be user be providing an object's address as input?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2012
    Posts
    27
    I want to be able to write the values from a start address to the given end address to a file.

    So the value starting at for example, *(hex+10) can be the first value written, to *(hex+20) when in reality the data starts from *(hex)

    So I just need to either check the address provided is within the program's allocation and that its within the hex malloc

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Sounds like you should be writing offsets instead, e.g., 10 and 20.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Apr 2012
    Posts
    27
    cheers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Searching for a particular address in a given range
    By Sjvlsdsd in forum C Programming
    Replies: 9
    Last Post: 07-30-2011, 08:22 AM
  2. random number within user entered range
    By me77 in forum C++ Programming
    Replies: 5
    Last Post: 03-10-2010, 08:11 PM
  3. validating memory - minimum address of valid location
    By m37h0d in forum C++ Programming
    Replies: 12
    Last Post: 09-05-2008, 10:50 PM
  4. Minimum valid address value
    By BMintern in forum C Programming
    Replies: 6
    Last Post: 04-12-2008, 08:21 AM
  5. Ignoring data after valid entered
    By wpr101 in forum C++ Programming
    Replies: 2
    Last Post: 01-16-2003, 02:55 PM