I can't seem to track down the issue. It's not consistent. I've run the html through online cleaners, copied from TextEdit, and it's happens with several documents and none of them have any odd characters in them.execution error at line 20 (LCB Error in file browser.lcb at line 409: cannot export char U+0000 in nul-terminated string buffer) near "foreign", char 47
cannot export char U+0000 in nul-terminated string buffer
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
cannot export char U+0000 in nul-terminated string buffer
I'm using a browser widget to display formatted documents. I frequently get an error:
-
- Livecode Opensource Backer
- Posts: 9287
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: cannot export char U+0000 in nul-terminated string buffer
That's odd.
U+0000 is the first null character in the Unicode "universe":
it will not show up as an "odd" character, it won't show up at all.
Personally I'd run it through a routine that specifically looks for U+0000 and replaces it
with something "boring" such as a SPACE (U+0020 = decimal 32).
U+0000 is the first null character in the Unicode "universe":
it will not show up as an "odd" character, it won't show up at all.
Personally I'd run it through a routine that specifically looks for U+0000 and replaces it
with something "boring" such as a SPACE (U+0020 = decimal 32).
-
- Livecode Opensource Backer
- Posts: 9287
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: cannot export char U+0000 in nul-terminated string buffer
Oh, Blast, didn't really register the problem is NOT the presence of a NULL char Ding An Sich,
but a null-terminated string buffer, or C-String:
https://en.wikipedia.org/wiki/Null-terminated_string
So, possibly, that's a problem with LCB's string variables:
"Many attempts made handling less error prone; moreso, making C string handling less error prone. One strategy is to add safer, encompassing functions such as strdup and strlcpy, whilst deprecating the use of unsafe functions such as gets. Another is to add an object-oriented wrapper around C strings so that only safe calls can be done."
If LCB string variables are null-terminated then the NULL termination chars have to be
stripped out or replaced with another char before an attempt is made to export them.
but a null-terminated string buffer, or C-String:
https://en.wikipedia.org/wiki/Null-terminated_string
So, possibly, that's a problem with LCB's string variables:
"Many attempts made handling less error prone; moreso, making C string handling less error prone. One strategy is to add safer, encompassing functions such as strdup and strlcpy, whilst deprecating the use of unsafe functions such as gets. Another is to add an object-oriented wrapper around C strings so that only safe calls can be done."
If LCB string variables are null-terminated then the NULL termination chars have to be
stripped out or replaced with another char before an attempt is made to export them.
-
- Livecode Opensource Backer
- Posts: 9287
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: cannot export char U+0000 in nul-terminated string buffer
Digging around:
"U+0000 NUL is forbidden in all versions of HTML. Although HTML5 CR specifies error handling rules for it in HTML parsing, NUL is known to cause problems in browsers. It might be argued that HTML rules do not apply to \0, which is just two printable Ascii characters as far as HTML is considered and gets interpreted as NUL by JavaScript interpreters. But using NUL that way in HTML documents violates at least the spirit of HTML and should not be expected to work reliably."
"U+0000 NUL is forbidden in all versions of HTML. Although HTML5 CR specifies error handling rules for it in HTML parsing, NUL is known to cause problems in browsers. It might be argued that HTML rules do not apply to \0, which is just two printable Ascii characters as far as HTML is considered and gets interpreted as NUL by JavaScript interpreters. But using NUL that way in HTML documents violates at least the spirit of HTML and should not be expected to work reliably."
-
- Livecode Opensource Backer
- Posts: 9287
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: cannot export char U+0000 in nul-terminated string buffer
On 28/12/2017 3:37 pm, Mark Waddingham via use-livecode wrote:
> In LCB a string is a string and a number is a number - there's an operator which tests whether a string 'looks like' a number and can optionally convert it.
>
> Strings in LCB are the same as in LCS - counted and not nul terminated (so they can contain the NUL 'char' - i.e. Code 0). It does have 'bridging' string types which are nul terminated - they are there to support calling a foreign functions which use such strings.
>
> Warmest Regards,
>
> Mark.
> In LCB a string is a string and a number is a number - there's an operator which tests whether a string 'looks like' a number and can optionally convert it.
>
> Strings in LCB are the same as in LCS - counted and not nul terminated (so they can contain the NUL 'char' - i.e. Code 0). It does have 'bridging' string types which are nul terminated - they are there to support calling a foreign functions which use such strings.
>
> Warmest Regards,
>
> Mark.
Re: cannot export char U+0000 in nul-terminated string buffer
@yeldarb: What version of LiveCode are you using? (Just so I can match up the error line to the correct version of the browser widget source file).
I'm guessing this is happening when a property is being set - my guess that it is 'the htmlText', and the string you are passing to 'the htmlText' contains a NUL byte. The reason this is an issue is that the browser widget uses C-strings to pass to the underlying browser object.
You could try:
This will remove the NUL bytes from tString - and so (hopefully) get rid of the problem.
I'm guessing this is happening when a property is being set - my guess that it is 'the htmlText', and the string you are passing to 'the htmlText' contains a NUL byte. The reason this is an issue is that the browser widget uses C-strings to pass to the underlying browser object.
You could try:
Code: Select all
replace numToChar(0) with empty in tString
set the <prop> to tString
Re: cannot export char U+0000 in nul-terminated string buffer
@yeldarb: Thanks - I've checked and that line is the call to the C function which 'sets a browser string property' - the C API uses a UTF-8 NUL terminated string - so you need to be careful to strip NULs from strings you use to pass to the browser via property setters in LiveCode Script.
(LCB handles the details of conversion internally, but it doesn't try to do things that don't make sense - and trying to create a NUL terminated string from a string which contains a NUL doesn't make sense - hence the error).
(LCB handles the details of conversion internally, but it doesn't try to do things that don't make sense - and trying to create a NUL terminated string from a string which contains a NUL doesn't make sense - hence the error).
Re: cannot export char U+0000 in nul-terminated string buffer
So I added the suggested line:
and that seems to have fixed the problem, thanks!
Code: Select all
replace numToChar(0) with empty in html