Jump to content
Sign in to follow this  
SlimShady

Null character

Recommended Posts

Why are null/nil characters not supported in AutoIt3?

Is it because when AutoIt sees the char it stops because every string ends with a null char?

Did some tests just now so my theory may be incorrect.

What I tried?

This...

$val = "Some" & Chr(0) & "text"
MsgBox(64, "Test", "$val: " & @CRLF & $val)

and this...

$val = "Some"
$val = $val & Chr(0) & "text"
MsgBox(64, "Test", "$val: " & @CRLF & $val)

and this...

$val = Chr(0) & "Sometext"
MsgBox(64, "Test", "$val: " & @CRLF & $val)

*..Maybe you ignore the char when we're storing it in a variable..*

I'm really curious.

Share this post


Link to post
Share on other sites

@SlimShady: toyour sample with Msgbox(), something from the MSDN-library:

"int MessageBox(

HWND hWnd, // handle of owner window

LPCTSTR lpText, // address of text in message box

LPCTSTR lpCaption, // address of title of message box

UINT uType // style of message box

);

Parameters

hWnd

Identifies the owner window of the message box to be created. If this parameter is NULL, the message box has no owner window.

lpText

Pointer to a null-terminated string containing the message to be displayed.

"

:lmao:

Edit: Ahhh, sorry, now I (hopefully) understand what you mean:

The text in the first sample should end after "some".

Hmmm...

Edited by Holger

Share this post


Link to post
Share on other sites

@SlimShady: toyour sample with Msgbox(), something from the MSDN-library:

"int MessageBox(

  HWND hWnd,          // handle of owner window

  LPCTSTR lpText,    // address of text in message box

  LPCTSTR lpCaption,  // address of title of message box

  UINT uType          // style of message box

);

Parameters

hWnd

Identifies the owner window of the message box to be created. If this parameter is NULL, the message box has no owner window.

lpText

Pointer to a null-terminated string containing the message to be displayed.

"

:lmao:

<{POST_SNAPBACK}>

I have seen that mentioned many times before.

That's why I didn't expect to see the full string in my tests.

But the strings are completely visible!

So I have a strong feeling that AutoIt ignores the null char.

Please explain what you do or don't do with null chars in strings/variables.

Share this post


Link to post
Share on other sites

I don't have any problems or requests or anything.

It's just a question I keep forgetting to ask.

And because Valik's RC4 Encrypt UDF is no 100% because AutoIt "can't handle" the null char.

So I wonder why AutoIt "can't handle" the null char.

BTW I did some more tests.

Check it out:

$val = "Sometext"
If StringInStr($val, "") Then MsgBox(64, "Test 1", "$val: " & @CRLF & $val)

$val = "Sometext"
If StringInStr($val, Chr(0)) Then MsgBox(64, "Test 2", "$val: " & @CRLF & $val)

$val = "Some" & Chr(0) & "text"
If StringInStr($val, Chr(0)) Then MsgBox(64, "Test 3", "$val: " & @CRLF & $val)

$val = "Some"
$val = $val & Chr(0) & "text"
If StringInStr($val, Chr(0)) Then MsgBox(64, "Test 4", "$val: " & @CRLF & $val)

$val = Chr(0) & "Sometext"
If StringInStr($val, Chr(0)) Then MsgBox(64, "Test 5", "$val: " & @CRLF & $val)
Edited by SlimShady

Share this post


Link to post
Share on other sites

All AutoIt's internal string handling mechanisms are based on the C-style string approach. This means that the terminating character for a string is the NULL character. For example:

const char *szString = "This is a test\0";  // \0 is implicit, but can be manually specified.

This example won't print completely in AutoIt:

const char *szString2 = "This\0 is a test";  // Any C-string based function only sees "This"

Now, when you call Chr(0), this is the string thats built:

const char *szString3 = "\0";

Now, given that the \0 terminates the string, any C-string based approach reads up to but not including the NULL character. So that means its an empty string. In AutoIt, that's the equivalent of:

Local $sString = ""

Therefore, because all the internal string stuff uses a C style approach, the NULL character isn't being inserted into the string like you think it should be. If AutoIt did not use a C style approach, then it would be because some other method would be used to terminate strings.

And since I see the inevitable, "Well, why not use some other method?" Because its hard. When you read a C-string, you know to stop when you see \0. This prevents you from running past the end of the string and getting in something elses memory which would lead to a crash. This means that in order not to use a terminating character, the strings have to carry around extraneous information such as its own size and its potential size. It also means rewriting a bunch of functions to operate on these strings. In the end, its a lot of code and a major pain in the ass. It probably needs done someday, but its a lot of work and a lot of potential to break a lot of things.

Share this post


Link to post
Share on other sites

Thanks for the info, Valik.

I was thinking and now I completely understand.

\0 (in C++) equals Chr(0) equals ""

The following explains the null character for me:

3 + 0 + 3

is like this:

$val = "Some" & Chr(0) & "text"

$val = "Some" & "" & "text"

That's why the null character is never visible and is only available for the programmer, the application and the computer.

Edited by SlimShady

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...