]> gitweb.michael.orlitzky.com - iconv-quirks.git/commitdiff
main.c: extend test_iconv_incomplete_multibyte_is_einval() with a suffix
authorMichael Orlitzky <michael@orlitzky.com>
Tue, 7 Jul 2026 13:58:05 +0000 (09:58 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Tue, 7 Jul 2026 13:58:05 +0000 (09:58 -0400)
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

diff --git a/main.c b/main.c
index 1b5d210cf4fd1edcf4363349c0689cc0f5e0cfa6..b5e2f61eb49659b9a8f4afebd8402e5123a573c4 100644 (file)
--- 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;