Changeset 6fe806a for owl.c


Ignore:
Timestamp:
Jan 17, 2008, 2:55:22 PM (17 years ago)
Author:
Alejandro R. Sedeño <asedeno@mit.edu>
Branches:
master, barnowl_perlaim, debian, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
625802a
Parents:
81312e4
Message:
better compliance with UTF-8 processing. Stop trying to pull in a UTF-8
character as soon as we know something has gone wrong.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • owl.c

    rb7b4565 r6fe806a  
    562562       
    563563        for (i = 1; i < bytes; i++) {
    564           utf8buf[i] = wgetch(typwin);
    565         }
    566         if (g_utf8_validate(utf8buf, -1, NULL)) {
    567           j.uch = g_utf8_get_char(utf8buf);
    568         }
    569         else {
    570           j.ch = ERR;
    571         }
     564          int tmp =  wgetch(typwin);
     565          /* If what we got was not a byte, or not a continuation byte */
     566          if (tmp > 0xff || !(tmp & 0x80 && ~tmp & 0x40)) {
     567            /* ill-formed UTF-8 code unit subsequence, put back the
     568               char we just got. */
     569            ungetch(tmp);
     570            j.ch = ERR;
     571            break;
     572          }
     573          utf8buf[i] = tmp;
     574        }
     575       
     576        if (j.ch != ERR) {
     577          if (g_utf8_validate(utf8buf, -1, NULL)) {
     578            j.uch = g_utf8_get_char(utf8buf);
     579          }
     580          else {
     581            j.ch = ERR;
     582          }
     583        }
    572584      }
    573585      else if (j.ch <= 0x7f) {
Note: See TracChangeset for help on using the changeset viewer.