Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7635025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:20:11+00:00 2026-05-31T07:20:11+00:00

Is it secure to do the following? MyClass* p = WantItInCase1(); if (p ==

  • 0

Is it secure to do the following?

MyClass* p = WantItInCase1();
if (p == NULL)
    p = 0x1;
else
   p = WantItInCase2();
if (p == NULL)
   p = 0x2;
...
CheckCases (p);  // we check '0x1' and '0x2' cases and otherwise process 'p' as normal object

I have a situation where MyClass objects can’t handle all variants needed in CheckCases(). So to avoid additional parameter is it possible to use this approach? At least I need a range of addresses that can’t be used for new allocations.

— Update —

Taking in account answers I decided to make some ‘tricky’ approach:

// somewhere in global definitions:
const MyClass* P_CASE_1 = (MyClass*) new int;
const MyClass* P_CASE_2 = (MyClass*) new int;
...
// previous code piece:
MyClass* p = WantItInCase1();
if (p == NULL)
    p = P_CASE_1;

It would be memory-safe, and it’s not dangerous to leak 4 bytes for each P_CASE_#.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T07:20:12+00:00Added an answer on May 31, 2026 at 7:20 am

    It depends on the OS 🙂

    To make it clear: on Windows 32 bits the last gb of address space is always reserved for the kernel, so you can use its addresses for your use. Normally it would be the last 2 gb of address space, but through a switch /3GB you can change it. A similar trick is used in the kernel for some data structures.

    I wouldn’t ever do it 🙂

    I’ll add that probably 0x1, 0x2, 0x3 are pretty safe, because the addresses given to you by the OS are normally at least 32 bits aligned, the 0x0 is defined for special purpose so the next three bytes won’t be allocated in a memory block. Aaah… Too much difficult to explain. Let’s say that the C runtime takes the memory from the OS, and that “standard” OS won’t ever give memory in the 0x0-0x3 range.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is the following a secure way of protecting a user only area? if(!isset($_SESSION['username'])){redirect(SITE_ROOT .
In C# I am binding to a secure LDAP site with the following code
Following my previous question as to whether ASP.net's default Page.IsPostBack implementation is secure (it's
i have the following customized security controller using the secure module for play: public
I'm using the following code to open a blank window from a secure page:
We get the following error; The request was aborted: Could not create SSL/TLS secure
I need to provide secure wiping function in windows mobile with following details: All
The Android developer docs say the following about Settings.Secure.HTTP_PROXY : Host name and port
I am trying to create a secure download web app with the following scenario.
I have the following code block which connects out to a secure service (payment

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.