[haiku-commits] Re: haiku: hrev48704 - docs/user/app

  • From: Stephan Aßmus <superstippi@xxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 22 Jan 2015 13:03:22 +0100

Hi,

Am 21.01.2015 um 21:29 schrieb John Scipione:
Axel Dörfler wrote:
Better, but why change "must" to "should"? It's definitely a must.

I disagree, I don't like to tell programmers what to do and I feel that
as a documentation writer it is my job to be humble and not assume too
much.

In technical documentation, the phrases "must", "must not", "should" and "should not" usually have a well defined (and different) meaning. The use of "must" is not offending or impolite.

I wrote the following program to test whether or not it is possible to
delete the message after assigning it to an Invoker via SetMessage().

#include <stdio.h>
#include <Invoker.h>
#include <Message.h>

int main()
{
     BInvoker* invoker = new BInvoker();
     BMessage* message = new BMessage();
     invoker->SetMessage(message);
     printf("The world is about to end\n");
     delete message;
     printf("This message should not appear, the world has ended.\n");

The text you are printing only shows that you don't understand what the problem is. If you were trying to use the BInvoker at this point, you should see problems. Maybe not at first, since you have not allocated new memory in the meantime, so while the BMessage pointer in the BInvoker points to freed memory, that memory has not been reused (overwritten) yet. So it may still look as if everything is fine. But it is not.

     delete invoker;
     printf("Now the world has definitely ended.\n");

At this point, you should get a crash due to an assertion in the memory allocator. But I think BMessage overwrites new and delete, and uses a custom allocator. Maybe that's why it is not crashing. Or maybe allocator does not reset some house-keeping values around the memory location of the pointer and that's why it doesn't crash.

     return 0;
}

This program compiled and ran without issue on R1A4 and appears to be
otherwise valid and correct, the world did not end, must is too
presumptuous.

I don't know why you thought your test program would prove your point. Maybe you need to understand what a double-free is and what consequences it can have. I have hinted at some above.

Best regards,
-Stephan



Other related posts: