Ignore:
File:
1 edited

Legend:

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

    rf4c8a83f r2544442  
    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, the actual
    55  *                      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 (0), the
     55 *                      actual 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);
    106108                }
    107                 free(new);
    108109        }
    109110
     
    155156                return EINVAL;
    156157        }
    157         if (ERROR_OCCURRED(async_data_write_finalize(callid, lengths,
    158             length))) {
     158        if(ERROR_OCCURRED(async_data_write_finalize(callid, lengths,
     159            sizeof(size_t) * (count + 1)))) {
    159160                free(lengths);
    160161                return ERROR_CODE;
     
    162163
    163164        *data = malloc(lengths[count]);
    164         if (!*data) {
     165        if (!(*data)) {
    165166                free(lengths);
    166167                return ENOMEM;
     
    170171        *strings = (measured_string_ref) malloc(sizeof(measured_string_t) *
    171172            count);
    172         if (!*strings) {
     173        if (!(*strings)) {
    173174                free(lengths);
    174175                free(*data);
     
    177178
    178179        next = *data;
    179         for (index = 0; index < count; index++) {
     180        for (index = 0; index < count; ++index) {
    180181                (*strings)[index].length = lengths[index];
    181182                if (lengths[index] > 0) {
    182                         if (!async_data_write_receive(&callid, &length) ||
     183                        if ((!async_data_write_receive(&callid, &length)) ||
    183184                            (length != lengths[index])) {
    184185                                free(*data);
     
    187188                                return EINVAL;
    188189                        }
    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                         }
     190                        ERROR_PROPAGATE(async_data_write_finalize(callid, next,
     191                            lengths[index]));
    196192                        (*strings)[index].value = next;
    197193                        next += lengths[index];
    198                         *next++ = '\0';
     194                        *next = '\0';
     195                        ++next;
    199196                } else {
    200197                        (*strings)[index].value = NULL;
     
    224221
    225222        length = 0;
    226         for (index = 0; index < count; index++) {
     223        for (index = 0; index < count; ++ index) {
    227224                lengths[index] = strings[index].length;
    228225                length += lengths[index] + 1;
     
    265262                return ENOMEM;
    266263
    267         if (!async_data_read_receive(&callid, &length) ||
     264        if ((!async_data_read_receive(&callid, &length)) ||
    268265            (length != sizeof(size_t) * (count + 1))) {
    269266                free(lengths);
    270267                return EINVAL;
    271268        }
    272         if (ERROR_OCCURRED(async_data_read_finalize(callid, lengths, length))) {
     269        if (ERROR_OCCURRED(async_data_read_finalize(callid, lengths,
     270            sizeof(size_t) * (count + 1)))) {
    273271                free(lengths);
    274272                return ERROR_CODE;
     
    276274        free(lengths);
    277275
    278         for (index = 0; index < count; index++) {
     276        for (index = 0; index < count; ++ index) {
    279277                if (strings[index].length > 0) {
    280                         if (!async_data_read_receive(&callid, &length) ||
     278                        if((!async_data_read_receive(&callid, &length)) ||
    281279                            (length != strings[index].length)) {
    282280                                return EINVAL;
     
    319317        char *next;
    320318
    321         if ((phone < 0) || (!strings) || (!data) || (count <= 0))
     319        if ((phone <= 0) || (!strings) || (!data) || (count <= 0))
    322320                return EINVAL;
    323321
     
    333331
    334332        *data = malloc(lengths[count]);
    335         if (!*data) {
     333        if (!(*data)) {
    336334                free(lengths);
    337335                return ENOMEM;
     
    340338        *strings = (measured_string_ref) malloc(sizeof(measured_string_t) *
    341339            count);
    342         if (!*strings) {
     340        if (!(*strings)) {
    343341                free(lengths);
    344342                free(*data);
     
    347345
    348346        next = *data;
    349         for (index = 0; index < count; index++) {
     347        for (index = 0; index < count; ++ index) {
    350348                (*strings)[index].length = lengths[index];
    351349                if (lengths[index] > 0) {
    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                         }
     350                        ERROR_PROPAGATE(async_data_read_start(phone, next,
     351                            lengths[index]));
    359352                        (*strings)[index].value = next;
    360353                        next += lengths[index];
    361                         *next++ = '\0';
     354                        *next = '\0';
     355                        ++ next;
    362356                } else {
    363357                        (*strings)[index].value = NULL;
     
    392386        size_t index;
    393387
    394         if ((phone < 0) || (!strings) || (count <= 0))
     388        if ((phone <= 0) || (!strings) || (count <= 0))
    395389                return EINVAL;
    396390
     
    407401        free(lengths);
    408402
    409         for (index = 0; index < count; index++) {
     403        for (index = 0; index < count; ++index) {
    410404                if (strings[index].length > 0) {
    411405                        ERROR_PROPAGATE(async_data_write_start(phone,
Note: See TracChangeset for help on using the changeset viewer.