Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 13441f1

Browse files
authored
Merge pull request #3787 from MoonlightSentinel/truncated-exception-message
Fix 20778 - Ensure that _d_print_throwable prints the entire message
2 parents 2f2a68e + f73bcf8 commit 13441f1

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

src/rt/dmain2.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ extern (C) void _d_print_throwable(Throwable t)
658658

659659
void sink(in char[] buf) scope nothrow
660660
{
661-
fprintf(stderr, "%.*s", cast(int)buf.length, buf.ptr);
661+
fwrite(buf.ptr, char.sizeof, buf.length, stderr);
662662
}
663663
formatThrowable(t, &sink);
664664
}

test/exceptions/Makefile

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
include ../common.mak
22

33
TESTS=stderr_msg unittest_assert invalid_memory_operation unknown_gc static_dtor \
4-
future_message refcounted rt_trap_exceptions_drt catch_in_finally
4+
future_message refcounted rt_trap_exceptions_drt catch_in_finally \
5+
message_with_null
56

67
ifeq ($(OS)-$(BUILD),linux-debug)
78
TESTS+=line_trace line_trace_21656 long_backtrace_trunc rt_trap_exceptions
@@ -77,13 +78,24 @@ $(ROOT)/catch_in_finally.done: STDERR_EXP="success."
7778
$(ROOT)/rt_trap_exceptions.done: STDERR_EXP="object.Exception@src/rt_trap_exceptions.d(12): this will abort"
7879
$(ROOT)/rt_trap_exceptions.done: STDERR_EXP2="src/rt_trap_exceptions.d:8 main"
7980
$(ROOT)/assert_fail.done: STDERR_EXP="success."
81+
82+
$(ROOT)/message_with_null.done: STDERR_EXP=" world"
83+
8084
$(ROOT)/%.done: $(ROOT)/%
8185
@echo Testing $*
8286
$(QUIET)$(TIMELIMIT)$(ROOT)/$* $(RUN_ARGS) 2>$(ROOT)/$*.stderr || true
83-
cat $(ROOT)/$*.stderr
84-
$(NEGATE) grep -qF $(STDERR_EXP) < $(ROOT)/$*.stderr
85-
if [ ! -z $(STDERR_EXP2) ] ; then \
86-
$(NEGATE) grep -qF $(STDERR_EXP2) < $(ROOT)/$*.stderr; \
87+
88+
@if $(NEGATE) grep -qF $(STDERR_EXP) < $(ROOT)/$*.stderr ; then true ; else \
89+
echo 'Searched for pattern $(STDERR_EXP), NEGATE = $(NEGATE)' ;\
90+
tail --bytes=5000 $(ROOT)/$*.stderr ;\
91+
exit 1 ;\
92+
fi
93+
@if [ ! -z $(STDERR_EXP2) ] ; then \
94+
if $(NEGATE) grep -qF $(STDERR_EXP2) < $(ROOT)/$*.stderr ; then true ; else \
95+
echo 'Searched for '$(STDERR_EXP2)' NEGATE = $(NEGATE)' ;\
96+
tail --bytes=5000 $(ROOT)/$*.stderr ;\
97+
exit 1 ;\
98+
fi \
8799
fi
88100
@touch $@
89101

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module message_with_null;
2+
3+
void main()
4+
{
5+
throw new Exception("hello\0 world!");
6+
}

0 commit comments

Comments
 (0)