From f4eb1ebec91fb305003e4352ca6dacf3a609c1a7 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Tue, 7 Jul 2026 09:58:05 -0400 Subject: [PATCH] main.c: extend test_iconv_incomplete_multibyte_is_einval() with a suffix Suffix or no, incomplete multibyte characters should cause an EINVAL, at least if we reach the end of the input. By adding a suffix parameter to this method, we make it easy to run through the list. --- main.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/main.c b/main.c index 1b5d210..b5e2f61 100644 --- a/main.c +++ b/main.c @@ -236,11 +236,26 @@ static int test_iconv_invalid_char_is_eilseq() { * Input conversion stopped due to an incomplete character or shift * sequence at the end of the input buffer. */ -static int test_iconv_incomplete_multibyte_is_einval() { +static int test_iconv_incomplete_multibyte_is_einval(char* suffix) { iconv_t cd; - const char* tocode = "UTF-8"; + const char* fromcode = "UTF-8"; + char* tocode = malloc(strlen(fromcode) + strlen(suffix) + 1); + sprintf(tocode, "%s%s", fromcode, suffix); + + char msg[59]; + char* tpl; + if (strlen(suffix) == 0) { + // Don't print the suffix, but do avoid warnings about + // the missing argument. + tpl = "iconv() incomplete multibyte is EINVAL%s..."; + } + else { + tpl = "iconv() incomplete multibyte is EINVAL (%s)..."; + } + snprintf(msg, 59, tpl, suffix); + printf("%-60s", msg); + - printf("%-60s", "iconv() returns EINVAL on incomplete multibyte..."); if (_my_iconv_open(&cd, tocode, tocode) == FAILURE) { printf("ERROR (iconv_open)\n"); return FAILURE; @@ -549,24 +564,25 @@ int main(int argc, char** argv) { result |= test_iconv_invalid_char_is_eilseq(); result |= test_iconv_too_big_is_e2big(); - result |= test_iconv_incomplete_multibyte_is_einval(); + result |= test_iconv_incomplete_multibyte_is_einval(""); result |= test_iconv_untranslatable(); if (ignore == SUCCESS) { result |= test_iconv_ignore_ignores_invalid(); result |= test_iconv_suffix_drops_untranslatable("//IGNORE"); - //result |= test_iconv_ignore_does_not_ignore_incomplete_multibyte(); + result |= test_iconv_incomplete_multibyte_is_einval("//IGNORE"); } if (translit == SUCCESS) { result |= test_translit_does_not_fail_on_untranslatable(); - //result |= test_translit_fails_on_incomplete_multibyte(); + result |= test_iconv_incomplete_multibyte_is_einval("//TRANSLIT"); + } if (non_identical_discard == SUCCESS) { result |= test_iconv_suffix_drops_untranslatable("//NON_IDENTICAL_DISCARD"); - //result |= test_nid_fails_on_incomplete_multibyte(); + result |= test_iconv_incomplete_multibyte_is_einval("//NON_IDENTICAL_DISCARD"); } return result; -- 2.53.0