octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #63930] fprintf writes incorrect characters wh


From: Markus Mützel
Subject: [Octave-bug-tracker] [bug #63930] fprintf writes incorrect characters when converting the encoding
Date: Sun, 2 Apr 2023 07:27:50 -0400 (EDT)

Follow-up Comment #45, bug #63930 (project octave):

There were still some issues with the latest patch. But the issue I am
currently stuck with seems to be with the conversion functions from gnulib.
Save the following code to, e.g., `test-u8-conv.c`:

#include "config.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "uniconv.h"

int main (void)
{
  char *tocode = "windows-1252";
  char src[3] = {230, 231, 10};
  size_t lengthp = 0;

  char *out_str = u8_conv_to_encoding (tocode, iconveh_question_mark,
                                       src, 3, NULL, NULL, &lengthp);

  printf ("lengthp = %d\n", lengthp);
  printf ("out_str = {");
  for (size_t i_out = 0; i_out < lengthp; i_out++)
      printf ("%d, ", out_str[i_out]);
  printf ("}\n");

  src[1] = 10;
  out_str = u8_conv_to_encoding (tocode, iconveh_question_mark,
                                 src, 2, NULL, NULL, &lengthp);

  printf ("lengthp = %d\n", lengthp);
  printf ("out_str = {");
  for (size_t i_out = 0; i_out < lengthp; i_out++)
      printf ("%d, ", out_str[i_out]);
  printf ("}\n");

  return 0;
}


And compile it in the Octave build tree with:

gcc test-u8-conv.c -otest_u8.exe -Ilibgnu -I../gnulib/lib -Llibgnu/.libs -lgnu
-liconv


The output for me (on Windows 11 with MinGW64 64-bit):

$ ./test_u8.exe
lengthp = 3
out_str = {63, 63, 10, }
lengthp = 0
out_str = {}


The first conversion replaced the invalid UTF-8 characters with 63 (i.e.,
"?").
I'd have expected that the second conversion resulted in {63, 10} (i.e.,
"?\n"). But it returns an empty string.

We could try to implement a workaround. But should this be fixed in gnulib
instead?



    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?63930>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]