FLTK logo

Re: [fltk.coredev] RFC: Small mod to fl_utf8len() to detect invalid single char UTF-8 bytes

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Library      Forums      Links      Apps     Login 
[  All Forums  |  Back to fltk.coredev  ]
 
[ Previous Message ] [ New Message | Reply ] [ Next Message ]

Re: RFC: Small mod to fl_utf8len() to detect invalid single char UTF-8 bytes Greg Ercolano 17:02 Aug 12  
 

On 8/12/26 09:30, Greg Ercolano wrote:

    I should mention though; FWIW, codex initially suggested rewriting the code to be as follows, as per RFC 3629:
  int fl_utf8len(char c) {
    const unsigned char u = (unsigned char)c;
    if (u <= 0x7f) return 1;
    if (u >= 0xc2 && u <= 0xdf) return 2;
    if (u >= 0xe0 && u <= 0xef) return 3;
    if (u >= 0xf0 && u <= 0xf4) return 4;
    return -1;
  }

  int fl_utf8len1(char c) {
    const int len = fl_utf8len(c);
    return len < 0 ? 1 : len;
  }
[..]

    Here's how it helps the test/terminal program which wants to demonstrate handling of invalid ANSI/XTERM/UTF-8 sequences, showing the difference between the old fl_utf8len(), which doesn't detect any of the 0xC0/1 and >0xF4 cases, vs new code suggested above by codex that detects all the single-byte issues. We probably should consider this change, as it probably prevents some accidental overruns from malformed utf-8:

--
You received this message because you are subscribed to the Google Groups "fltk.coredev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkcoredev+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/fltkcoredev/88bbb128-036b-4116-8dc4-3fa6fdfe4bd5%40seriss.com.
[ Direct Link to Message ]
 
     
[ Previous Message ] [ New Message | Reply ] [ Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2026 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.