Ignore:
Timestamp:
2010-10-27T20:33:51Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f4c8a83f
Parents:
6067284
Message:

Measured strings nits.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/adt/measured_strings.c

    r6067284 rd2b1040  
    5252 * @param[in] string    The initial character string to be stored.
    5353 * @param[in] length    The length of the given string without the terminating
    54  *                      zero ('/0') character. If the length is zero (0), the
    55  *                      actual length is computed. The given length is used and
    56  *                      appended with the terminating zero ('\\0') character
     54 *                      zero ('\0') character. If the length is zero, the actual
     55 *                      length is computed. The given length is used and
     56 *                      appended with the terminating zero ('\0') character
    5757 *                      otherwise.
    5858 * @returns             The new bundled character string with measured length.
     
    6060 */
    6161measured_string_ref
    62 measured_string_create_bulk(const char * string, size_t length)
     62measured_string_create_bulk(const char *string, size_t length)
    6363{
    6464        measured_string_ref new;
     
    6666        if (length == 0) {
    6767                while (string[length])
    68                         ++length;
     68                        length++;
    6969        }
    7070        new = (measured_string_ref) malloc(sizeof(measured_string_t) +
     
    104104                        new->value[new->length] = '\0';
    105105                        return new;
    106                 } else {
    107                         free(new);
    108106                }
     107                free(new);
    109108        }
    110109
     
    156155                return EINVAL;
    157156        }
    158         if(ERROR_OCCURRED(async_data_write_finalize(callid, lengths,
    159             sizeof(size_t) * (count + 1)))) {
     157        if (ERROR_OCCURRED(async_data_write_finalize(callid, lengths,
     158            length))) {
    160159                free(lengths);
    161160                return ERROR_CODE;
     
    163162
    164163        *data = malloc(lengths[count]);
    165         if (!(*data)) {
     164        if (!*data) {
    166165                free(lengths);
    167166                return ENOMEM;
     
    171170        *strings = (measured_string_ref) malloc(sizeof(measured_string_t) *
    172171            count);
    173         if (!(*strings)) {
     172        if (!*strings) {
    174173                free(lengths);
    175174                free(*data);
     
    178177
    179178        next = *data;
    180         for (index = 0; index < count; ++index) {
     179        for (index = 0; index < count; index++) {
    181180                (*strings)[index].length = lengths[index];
    182181                if (lengths[index] > 0) {
    183                         if ((!async_data_write_receive(&callid, &length)) ||
     182                        if (!async_data_write_receive(&callid, &length) ||
    184183                            (length != lengths[index])) {
    185184                                free(*data);
     
    192191                        (*strings)[index].value = next;
    193192                        next += lengths[index];
    194                         *next = '\0';
    195                         ++next;
     193                        *next++ = '\0';
    196194                } else {
    197195                        (*strings)[index].value = NULL;
     
    221219
    222220        length = 0;
    223         for (index = 0; index < count; ++ index) {
     221        for (index = 0; index < count; index++) {
    224222                lengths[index] = strings[index].length;
    225223                length += lengths[index] + 1;
     
    262260                return ENOMEM;
    263261
    264         if ((!async_data_read_receive(&callid, &length)) ||
     262        if (!async_data_read_receive(&callid, &length) ||
    265263            (length != sizeof(size_t) * (count + 1))) {
    266264                free(lengths);
    267265                return EINVAL;
    268266        }
    269         if (ERROR_OCCURRED(async_data_read_finalize(callid, lengths,
    270             sizeof(size_t) * (count + 1)))) {
     267        if (ERROR_OCCURRED(async_data_read_finalize(callid, lengths, length))) {
    271268                free(lengths);
    272269                return ERROR_CODE;
     
    274271        free(lengths);
    275272
    276         for (index = 0; index < count; ++ index) {
     273        for (index = 0; index < count; index++) {
    277274                if (strings[index].length > 0) {
    278                         if((!async_data_read_receive(&callid, &length)) ||
     275                        if (!async_data_read_receive(&callid, &length) ||
    279276                            (length != strings[index].length)) {
    280277                                return EINVAL;
     
    317314        char *next;
    318315
    319         if ((phone <= 0) || (!strings) || (!data) || (count <= 0))
     316        if ((phone < 0) || (!strings) || (!data) || (count <= 0))
    320317                return EINVAL;
    321318
     
    331328
    332329        *data = malloc(lengths[count]);
    333         if (!(*data)) {
     330        if (!*data) {
    334331                free(lengths);
    335332                return ENOMEM;
     
    338335        *strings = (measured_string_ref) malloc(sizeof(measured_string_t) *
    339336            count);
    340         if (!(*strings)) {
     337        if (!*strings) {
    341338                free(lengths);
    342339                free(*data);
     
    345342
    346343        next = *data;
    347         for (index = 0; index < count; ++ index) {
     344        for (index = 0; index < count; index++) {
    348345                (*strings)[index].length = lengths[index];
    349346                if (lengths[index] > 0) {
     
    352349                        (*strings)[index].value = next;
    353350                        next += lengths[index];
    354                         *next = '\0';
    355                         ++ next;
     351                        *next++ = '\0';
    356352                } else {
    357353                        (*strings)[index].value = NULL;
     
    386382        size_t index;
    387383
    388         if ((phone <= 0) || (!strings) || (count <= 0))
     384        if ((phone < 0) || (!strings) || (count <= 0))
    389385                return EINVAL;
    390386
     
    401397        free(lengths);
    402398
    403         for (index = 0; index < count; ++index) {
     399        for (index = 0; index < count; index++) {
    404400                if (strings[index].length > 0) {
    405401                        ERROR_PROPAGATE(async_data_write_start(phone,
Note: See TracChangeset for help on using the changeset viewer.