Skip to content
  • Philip Withnall's avatar
    gconvert: Fix error handling for g_iconv() with unrepresentable chars · 8abf3a04
    Philip Withnall authored
    The behaviour of upstream iconv() when faced with a character which is
    valid in the input encoding, but not representable in the output
    encoding, is implementation defined:
    
    http://pubs.opengroup.org/onlinepubs/9699919799/
    
    
    
    Specifically:
    
       If iconv() encounters a character in the input buffer that is valid,
       but for which an identical character does not exist in the target
       codeset, iconv() shall perform an implementation-defined conversion
       on this character.
    
    This behaviour was being exposed in our g_iconv() wrapper and also in
    g_convert_with_iconv() — but users of g_convert_with_iconv() (both the
    GLib unit tests, and the implementation of g_convert_with_fallback())
    were assuming that iconv() would return EILSEQ if faced with an
    unrepresentable character.
    
    On platforms like NetBSD, this is not the case: NetBSD’s iconv()
    finishes the conversion successfully, and outputs a string containing
    replacement characters. It signals those replacements in its return
    value from iconv(), which is positive (specifically, non-zero) in such a
    case.
    
    Let’s codify the existing assumed behaviour of g_convert_with_iconv(),
    documenting that it will return G_CONVERT_ERROR_INVALID_SEQUENCE if
    faced with an unrepresentable character. As g_iconv() is a thin wrapper
    around iconv(), leave the behaviour there implementation-defined (but
    document it as such).
    
    Signed-off-by: default avatarPhilip Withnall <withnall@endlessm.com>
    
    https://bugzilla.gnome.org/show_bug.cgi?id=790698
    8abf3a04