Changeset b06414f in mainline for uspace/lib/c/generic/str.c


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.

File:
1 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;
Note: See TracChangeset for help on using the changeset viewer.