Ignore:
File:
1 edited

Legend:

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

    r2544442 rf4c8a83f  
    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);
     
    188187                                return EINVAL;
    189188                        }
    190                         ERROR_PROPAGATE(async_data_write_finalize(callid, next,
    191                             lengths[index]));
     189                        if (ERROR_OCCURRED(async_data_write_finalize(callid,
     190                            next, lengths[index]))) {
     191                                free(*data);
     192                                free(*strings);
     193                                free(lengths);
     194                                return ERROR_CODE;
     195                        }
    192196                        (*strings)[index].value = next;
    193197                        next += lengths[index];
    194                         *next = '\0';
    195                         ++next;
     198                        *next++ = '\0';
    196199                } else {
    197200                        (*strings)[index].value = NULL;
     
    221224
    222225        length = 0;
    223         for (index = 0; index < count; ++ index) {
     226        for (index = 0; index < count; index++) {
    224227                lengths[index] = strings[index].length;
    225228                length += lengths[index] + 1;
     
    262265                return ENOMEM;
    263266
    264         if ((!async_data_read_receive(&callid, &length)) ||
     267        if (!async_data_read_receive(&callid, &length) ||
    265268            (length != sizeof(size_t) * (count + 1))) {
    266269                free(lengths);
    267270                return EINVAL;
    268271        }
    269         if (ERROR_OCCURRED(async_data_read_finalize(callid, lengths,
    270             sizeof(size_t) * (count + 1)))) {
     272        if (ERROR_OCCURRED(async_data_read_finalize(callid, lengths, length))) {
    271273                free(lengths);
    272274                return ERROR_CODE;
     
    274276        free(lengths);
    275277
    276         for (index = 0; index < count; ++ index) {
     278        for (index = 0; index < count; index++) {
    277279                if (strings[index].length > 0) {
    278                         if((!async_data_read_receive(&callid, &length)) ||
     280                        if (!async_data_read_receive(&callid, &length) ||
    279281                            (length != strings[index].length)) {
    280282                                return EINVAL;
     
    317319        char *next;
    318320
    319         if ((phone <= 0) || (!strings) || (!data) || (count <= 0))
     321        if ((phone < 0) || (!strings) || (!data) || (count <= 0))
    320322                return EINVAL;
    321323
     
    331333
    332334        *data = malloc(lengths[count]);
    333         if (!(*data)) {
     335        if (!*data) {
    334336                free(lengths);
    335337                return ENOMEM;
     
    338340        *strings = (measured_string_ref) malloc(sizeof(measured_string_t) *
    339341            count);
    340         if (!(*strings)) {
     342        if (!*strings) {
    341343                free(lengths);
    342344                free(*data);
     
    345347
    346348        next = *data;
    347         for (index = 0; index < count; ++ index) {
     349        for (index = 0; index < count; index++) {
    348350                (*strings)[index].length = lengths[index];
    349351                if (lengths[index] > 0) {
    350                         ERROR_PROPAGATE(async_data_read_start(phone, next,
    351                             lengths[index]));
     352                        if (ERROR_OCCURRED(async_data_read_start(phone, next,
     353                            lengths[index]))) {
     354                                free(lengths);
     355                                free(data);
     356                                free(strings);
     357                                return ERROR_CODE;
     358                        }
    352359                        (*strings)[index].value = next;
    353360                        next += lengths[index];
    354                         *next = '\0';
    355                         ++ next;
     361                        *next++ = '\0';
    356362                } else {
    357363                        (*strings)[index].value = NULL;
     
    386392        size_t index;
    387393
    388         if ((phone <= 0) || (!strings) || (count <= 0))
     394        if ((phone < 0) || (!strings) || (count <= 0))
    389395                return EINVAL;
    390396
     
    401407        free(lengths);
    402408
    403         for (index = 0; index < count; ++index) {
     409        for (index = 0; index < count; index++) {
    404410                if (strings[index].length > 0) {
    405411                        ERROR_PROPAGATE(async_data_write_start(phone,
Note: See TracChangeset for help on using the changeset viewer.