digitalmars.D.learn - uncaught exceptions: stack trace truncated at NUL char
- kdevel (32/32) Dec 13 2020 ~~~char2.d
- KapyoniK (4/18) Dec 13 2020 Is it really a bug ? \0 truncates the string, as mentionned on
- kdevel (2/5) Dec 13 2020 I thought the D runtime is written in D (with D strings)?!?
- rikki cattermole (3/9) Dec 13 2020 String literals are null terminated by the compiler. It is very useful
- kdevel (8/10) Dec 13 2020 On Sunday, 13 December 2020 at 20:58:42 UTC, rikki cattermole
- Paul Backus (5/15) Dec 13 2020 This is definitely a bug. The problem is that the D runtime uses
- kdevel (2/3) Dec 13 2020 filed as Issue 21480
~~~char2.d void main () { import std.stdio; import std.conv; char [2] win = [0, 'X']; auto ne = new Exception ("A " ~ win.to!string ~ " B"); try throw ne; catch (Exception e) writeln ("exception caught: e.msg = <", e.msg, ">"); throw ne; } ~~~ Output: exception caught: e.msg = <A X B> object.Exception char2.d(6): A <--- truncated at \0 [...] $ ./char2 | hexdump -c 0000000 e x c e p t i o n c a u g h t 0000010 : e . m s g = < A \0 X 0000020 B > \n $ ./char2 2>&1 1>/dev/null |hexdump -c 0000000 o b j e c t . E x c e p t i o n 0000010 c h a r 2 . d ( 6 ) : A \n 0000020 - - - - - - - - - - - - - - - - [...] Shall I file a bug?
Dec 13 2020
On Sunday, 13 December 2020 at 11:51:19 UTC, kdevel wrote:~~~char2.d void main () { import std.stdio; import std.conv; char [2] win = [0, 'X']; auto ne = new Exception ("A " ~ win.to!string ~ " B"); try throw ne; catch (Exception e) writeln ("exception caught: e.msg = <", e.msg, ">"); throw ne; } ~~~ [...]Is it really a bug ? \0 truncates the string, as mentionned on this page : https://en.wikipedia.org/wiki/Null-terminated_string
Dec 13 2020
On Sunday, 13 December 2020 at 20:25:06 UTC, KapyoniK wrote:Is it really a bug ? \0 truncates the string, as mentionned on this page : https://en.wikipedia.org/wiki/Null-terminated_stringI thought the D runtime is written in D (with D strings)?!?
Dec 13 2020
On 14/12/2020 9:56 AM, kdevel wrote:On Sunday, 13 December 2020 at 20:25:06 UTC, KapyoniK wrote:String literals are null terminated by the compiler. It is very useful for communicating with C.Is it really a bug ? \0 truncates the string, as mentionned on this page : https://en.wikipedia.org/wiki/Null-terminated_stringI thought the D runtime is written in D (with D strings)?!?
Dec 13 2020
On Sunday, 13 December 2020 at 20:58:42 UTC, rikki cattermole wrote: [...]String literals are null terminated by the compiler. It is very useful for communicating with C.Sure, but in the example given there is an embedded NUL which as part of an exception msg. If caught everything works as expected, but if the stack is unwound the information is lost due to truncation.
Dec 13 2020
On Sunday, 13 December 2020 at 21:22:16 UTC, kdevel wrote:On Sunday, 13 December 2020 at 20:58:42 UTC, rikki cattermole wrote: [...]This is definitely a bug. The problem is that the D runtime uses `fprintf` to print the exception's error message, when it should be using `fwrite`: https://github.com/dlang/druntime/blob/v2.094.2/src/rt/dmain2.d#L733String literals are null terminated by the compiler. It is very useful for communicating with C.Sure, but in the example given there is an embedded NUL which as part of an exception msg. If caught everything works as expected, but if the stack is unwound the information is lost due to truncation.
Dec 13 2020
On Sunday, 13 December 2020 at 22:40:53 UTC, Paul Backus wrote:This is definitely a bug.filed as Issue 21480
Dec 13 2020