Changes in uspace/lib/c/generic/adt/measured_strings.c [f4c8a83f:2544442] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/adt/measured_strings.c
rf4c8a83f r2544442 52 52 * @param[in] string The initial character string to be stored. 53 53 * @param[in] length The length of the given string without the terminating 54 * zero (' \0') character. If the length is zero, the actual55 * length is computed. The given length is used and56 * appended with the terminating zero ('\ 0') character54 * 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 57 57 * otherwise. 58 58 * @returns The new bundled character string with measured length. … … 60 60 */ 61 61 measured_string_ref 62 measured_string_create_bulk(const char * string, size_t length)62 measured_string_create_bulk(const char * string, size_t length) 63 63 { 64 64 measured_string_ref new; … … 66 66 if (length == 0) { 67 67 while (string[length]) 68 length++;68 ++length; 69 69 } 70 70 new = (measured_string_ref) malloc(sizeof(measured_string_t) + … … 104 104 new->value[new->length] = '\0'; 105 105 return new; 106 } else { 107 free(new); 106 108 } 107 free(new);108 109 } 109 110 … … 155 156 return EINVAL; 156 157 } 157 if 158 length))) {158 if(ERROR_OCCURRED(async_data_write_finalize(callid, lengths, 159 sizeof(size_t) * (count + 1)))) { 159 160 free(lengths); 160 161 return ERROR_CODE; … … 162 163 163 164 *data = malloc(lengths[count]); 164 if (! *data) {165 if (!(*data)) { 165 166 free(lengths); 166 167 return ENOMEM; … … 170 171 *strings = (measured_string_ref) malloc(sizeof(measured_string_t) * 171 172 count); 172 if (! *strings) {173 if (!(*strings)) { 173 174 free(lengths); 174 175 free(*data); … … 177 178 178 179 next = *data; 179 for (index = 0; index < count; index++) {180 for (index = 0; index < count; ++index) { 180 181 (*strings)[index].length = lengths[index]; 181 182 if (lengths[index] > 0) { 182 if ( !async_data_write_receive(&callid, &length) ||183 if ((!async_data_write_receive(&callid, &length)) || 183 184 (length != lengths[index])) { 184 185 free(*data); … … 187 188 return EINVAL; 188 189 } 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])); 196 192 (*strings)[index].value = next; 197 193 next += lengths[index]; 198 *next++ = '\0'; 194 *next = '\0'; 195 ++next; 199 196 } else { 200 197 (*strings)[index].value = NULL; … … 224 221 225 222 length = 0; 226 for (index = 0; index < count; index++) {223 for (index = 0; index < count; ++ index) { 227 224 lengths[index] = strings[index].length; 228 225 length += lengths[index] + 1; … … 265 262 return ENOMEM; 266 263 267 if ( !async_data_read_receive(&callid, &length) ||264 if ((!async_data_read_receive(&callid, &length)) || 268 265 (length != sizeof(size_t) * (count + 1))) { 269 266 free(lengths); 270 267 return EINVAL; 271 268 } 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)))) { 273 271 free(lengths); 274 272 return ERROR_CODE; … … 276 274 free(lengths); 277 275 278 for (index = 0; index < count; index++) {276 for (index = 0; index < count; ++ index) { 279 277 if (strings[index].length > 0) { 280 if (!async_data_read_receive(&callid, &length)||278 if((!async_data_read_receive(&callid, &length)) || 281 279 (length != strings[index].length)) { 282 280 return EINVAL; … … 319 317 char *next; 320 318 321 if ((phone < 0) || (!strings) || (!data) || (count <= 0))319 if ((phone <= 0) || (!strings) || (!data) || (count <= 0)) 322 320 return EINVAL; 323 321 … … 333 331 334 332 *data = malloc(lengths[count]); 335 if (! *data) {333 if (!(*data)) { 336 334 free(lengths); 337 335 return ENOMEM; … … 340 338 *strings = (measured_string_ref) malloc(sizeof(measured_string_t) * 341 339 count); 342 if (! *strings) {340 if (!(*strings)) { 343 341 free(lengths); 344 342 free(*data); … … 347 345 348 346 next = *data; 349 for (index = 0; index < count; index++) {347 for (index = 0; index < count; ++ index) { 350 348 (*strings)[index].length = lengths[index]; 351 349 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])); 359 352 (*strings)[index].value = next; 360 353 next += lengths[index]; 361 *next++ = '\0'; 354 *next = '\0'; 355 ++ next; 362 356 } else { 363 357 (*strings)[index].value = NULL; … … 392 386 size_t index; 393 387 394 if ((phone < 0) || (!strings) || (count <= 0))388 if ((phone <= 0) || (!strings) || (count <= 0)) 395 389 return EINVAL; 396 390 … … 407 401 free(lengths); 408 402 409 for (index = 0; index < count; index++) {403 for (index = 0; index < count; ++index) { 410 404 if (strings[index].length > 0) { 411 405 ERROR_PROPAGATE(async_data_write_start(phone,
Note:
See TracChangeset
for help on using the changeset viewer.