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 8948169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:55:17+00:00 2026-06-15T12:55:17+00:00

I was reading Moai source code, and I became curious about why this should

  • 0

I was reading Moai source code, and I became curious about why this should cause a crash (or not…)

I do not really understood that snippet.

In file A:

#define UNUSED(p) (( void )p)

In file B:

//----------------------------------------------------------------//
/** @name   crash
    @text   Crashes Moai with a null pointer dereference.

    @out    nil
*/
int MOAISim::_crash ( lua_State* L ) {
    UNUSED(L);

    int *p = NULL;
    (*p) = 0;

    return 0;
}

EDIT:

I think part of what I was not understanding is what “deference” means. So if you put that in your answers it would be awesome.

  • 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-06-15T12:55:18+00:00Added an answer on June 15, 2026 at 12:55 pm

    The crash is caused by the dereference of the null pointer:

    (*p) = 0; // <--- Crash
    

    Also as pointed out in the comments, the UNUSED macros is only there to suppress the “unused parameter” warning that most compilers will give.

    It is usually also possible to prevent the warning by, simply, not specifying the variable name as follows:

    int MOAISim::_crash ( lua_State* ) 
    {
        int *p = NULL;
        (*p) = 0;
    
        return 0;
    }
    

    It’s also worth bearing in mind that the above is not a guaranteed crash. On one of the 32-bit consoles de-referencing a null pointer actually resulted in the number “3”. This did make null dereferences quite hard to find, but generally if you saw a 3 sitting around in a register you could hazard a good guess as to what had just gone wrong.

    Dereferencing is essentially asking for the value stored at a given pointer. If the pointer is not valid (that is, pointing at a memory location that the process does not own) then it results in a crash. In Windows this is called an Access Violation (0xC0000005). Under Linux it’s a Segmentation Violation, SIGSEGV.

    See also

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

Sidebar

Related Questions

Reading the Oxite source code, I have found that validators save bad property name
Reading through this excellent article about safe construction techniques by Brain Goetz, I got
Reading this question I found this as (note the quotation marks) code to solve
Reading about the G.729 codec , I found this interesting tidbit about Comfort Noise
Reading the code of many javascript libraries, I see that many developers use to
Reading source code of my current project, I see: [self retain] in one class,
Reading code from other posts, I'm seeing something like this. struct Foo { Foo()
Reading about the GitHub wikis, I saw that they support several lightweight markup languages
Reading this excellent answer about password hashing and wondering how to implement it: The
Reading the code of the C library's sockets interface, I found this: /* Types

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.