Changeset 4f4018b in mainline


Ignore:
Timestamp:
2019-02-05T15:25:50Z (5 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
cca2d93b
Parents:
472fe7a
Message:

Do not misuse printf_size() to estimate byte size of output

The incorrectly named function actually counts unicode code
points.

Location:
uspace/lib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/io/asprintf.c

    r472fe7a r4f4018b  
    8686        va_list args2;
    8787        va_copy(args2, args);
    88         int ret = vprintf_size(fmt, args2);
     88        int ret = vsnprintf(NULL, 0, fmt, args2);
    8989        va_end(args2);
    9090
    9191        if (ret > 0) {
    92                 *strp = malloc(STR_BOUNDS(ret) + 1);
     92                *strp = malloc(ret + 1);
    9393                if (*strp == NULL)
    9494                        return -1;
    9595
    96                 vsnprintf(*strp, STR_BOUNDS(ret) + 1, fmt, args);
     96                vsnprintf(*strp, ret + 1, fmt, args);
    9797        }
    9898
  • uspace/lib/http/src/headers.c

    r472fe7a r4f4018b  
    8585{
    8686        /* TODO properly split long header values */
    87         if (buf == NULL) {
    88                 return printf_size(HTTP_HEADER_LINE, header->name, header->value);
    89         } else {
    90                 return snprintf(buf, buf_size,
    91                     HTTP_HEADER_LINE, header->name, header->value);
    92         }
     87        return snprintf(buf, buf_size,
     88            HTTP_HEADER_LINE, header->name, header->value);
    9389}
    9490
  • uspace/lib/http/src/request.c

    r472fe7a r4f4018b  
    8282    const char *method, const char *path)
    8383{
    84         if (buf == NULL) {
    85                 return printf_size(HTTP_METHOD_LINE, method, path);
    86         } else {
    87                 return snprintf(buf, buf_size, HTTP_METHOD_LINE, method, path);
    88         }
     84        return snprintf(buf, buf_size, HTTP_METHOD_LINE, method, path);
    8985}
    9086
Note: See TracChangeset for help on using the changeset viewer.