From 6fcb51cea28cc197a89466ac44122c6217638887 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sat, 15 Jan 2022 17:11:40 +0100 Subject: [PATCH] add warning when encoded string contains 0-byte --- compiler/src/prog8/compiler/astprocessing/AstChecker.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt index 2afc2587a..c748186f8 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt @@ -794,7 +794,9 @@ internal class AstChecker(private val program: Program, checkValueTypeAndRangeString(DataType.STR, string) try { // just *try* if it can be encoded, don't actually do it - compilerOptions.compTarget.encodeString(string.value, string.altEncoding) + val bytes = compilerOptions.compTarget.encodeString(string.value, string.altEncoding) + if(0u in bytes) + errors.warn("a character in the string encodes into the 0-byte, which will terminate the string prematurely", string.position) } catch (cx: CharConversionException) { errors.err(cx.message ?: "can't encode string", string.position) }