Changeset b06414f in mainline


Ignore:
Timestamp:
2017-05-19T14:04:36Z (8 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e540bc87
Parents:
2628642
Message:

Use proper sizes for buffers holding conversions from/to UTF-16 LFN's

FAT uses UTF-16 for encoding long file names. HelenOS needs to convert
these strings into and from its native UTF-8 encoding. The size of the
UTF-8 buffer in bytes needs to be at least 4 times the number of
characters in a LFN.

Location:
uspace
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/str.c

    r2628642 rb06414f  
    951951}
    952952
    953 int str_to_utf16(uint16_t *dest, size_t size, const char *src)
     953/** Convert string to UTF16 string.
     954 *
     955 * Convert string @a src to utf16 string. The output is written to the buffer
     956 * specified by @a dest and @a dlen. @a dlen must be non-zero and the string
     957 * written will always be well-formed. Surrogate pairs also supported.
     958 *
     959 * @param dest  Destination buffer.
     960 * @param dlen  Number of utf16 characters that fit in the destination buffer.
     961 * @param src   Source string.
     962 *
     963 * @return EOK, if success, negative otherwise.
     964 */
     965int str_to_utf16(uint16_t *dest, size_t dlen, const char *src)
    954966{
    955967        int rc = EOK;
     
    958970        wchar_t c;
    959971
    960         assert(size > 0);
     972        assert(dlen > 0);
    961973       
    962974        while ((c = str_decode(src, &offset, STR_NO_LIMIT)) != 0) {
    963975                if (c > 0x10000) {
    964                         if (idx + 2 >= size - 1) {
     976                        if (idx + 2 >= dlen - 1) {
    965977                                rc = EOVERFLOW;
    966978                                break;
     
    975987
    976988                idx++;
    977                 if (idx >= size - 1) {
     989                if (idx >= dlen - 1) {
    978990                        rc = EOVERFLOW;
    979991                        break;
  • uspace/lib/c/include/str.h

    r2628642 rb06414f  
    9898extern wchar_t *str_to_awstr(const char *src);
    9999extern int utf16_to_str(char *dest, size_t size, const uint16_t *src);
    100 extern int str_to_utf16(uint16_t *dest, size_t size, const char *src);
     100extern int str_to_utf16(uint16_t *dest, size_t dlen, const char *src);
    101101
    102102extern char *str_chr(const char *str, wchar_t ch);
  • uspace/srv/fs/fat/fat_dentry.h

    r2628642 rb06414f  
    8383#define FAT_LFN_CHKSUM(d) ((d)->lfn.check_sum)
    8484
    85 #define FAT_LFN_NAME_SIZE   260
     85#define FAT_LFN_NAME_LEN    260                           /* characters */
     86#define FAT_LFN_NAME_SIZE   STR_BOUNDS(FAT_LFN_NAME_LEN)  /* bytes */
    8687#define FAT_LFN_MAX_COUNT   20
    8788#define FAT_LFN_PART1_SIZE  5
  • uspace/srv/fs/fat/fat_directory.c

    r2628642 rb06414f  
    155155{
    156156        fat_dentry_t *d = NULL;
    157         uint16_t wname[FAT_LFN_NAME_SIZE];
     157        uint16_t wname[FAT_LFN_NAME_LEN];
    158158        size_t lfn_offset, lfn_size;
    159159        bool long_entry = false;
     
    293293                int long_entry_count;
    294294                uint8_t checksum;
    295                 uint16_t wname[FAT_LFN_NAME_SIZE];
     295                uint16_t wname[FAT_LFN_NAME_LEN];
    296296                size_t lfn_size, lfn_offset;
    297297               
    298                 rc = str_to_utf16(wname, FAT_LFN_NAME_SIZE, name);
     298                rc = str_to_utf16(wname, FAT_LFN_NAME_LEN, name);
    299299                if (rc != EOK)
    300300                        return rc;
Note: See TracChangeset for help on using the changeset viewer.