Differences From Artifact [75be1c56bd]:
- File src/OFString.m — part of check-in [9d74d1b74e] at 2020-11-06 02:12:39 on branch trunk — OFData: Make parameter order more consistent (user: js, size: 65777) [annotate] [blame] [check-ins using]
To Artifact [ab9d9164f8]:
- File
src/OFString.m
— part of check-in
[a2b4238850]
at
2020-11-06 02:24:14
on branch trunk
— Future-proof some code using freeWhenDone
While -[OFData initWithDataNoCopy:count:itemSize:freeWhenDone:] can
currently never throw, it might in the future, and when it does so in
the future, these would be memory leaks then. (user: js, size: 65979) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
1045 1046 1047 1048 1049 1050 1051 | tmp[(size_t)fileSize] = '\0'; } @catch (id e) { [self release]; @throw e; } | | > | | | > > > > | | 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 | tmp[(size_t)fileSize] = '\0'; } @catch (id e) { [self release]; @throw e; } if (encoding == OF_STRING_ENCODING_UTF_8) { @try { self = [self initWithUTF8StringNoCopy: tmp length: (size_t)fileSize freeWhenDone: true]; } @catch (id e) { free(tmp); @throw e; } } else { @try { self = [self initWithCString: tmp encoding: encoding length: (size_t)fileSize]; } @finally { free(tmp); } |
︙ | ︙ | |||
1431 1432 1433 1434 1435 1436 1437 | } break; default: @throw [OFInvalidEncodingException exception]; } | > | | | > > > > | 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 | } break; default: @throw [OFInvalidEncodingException exception]; } @try { return [OFData dataWithItemsNoCopy: cString count: cStringLength + 1 freeWhenDone: true].items; } @catch (id e) { free(cString); @throw e; } } - (const char *)cStringWithEncoding: (of_string_encoding_t)encoding { return [self of_cStringWithEncoding: encoding lossy: false]; } |
︙ | ︙ | |||
2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 | size_t length = self.length; of_unichar_t *buffer; buffer = of_malloc(length, sizeof(of_unichar_t)); @try { [self getCharacters: buffer inRange: of_range(0, length)]; } @catch (id e) { free(buffer); @throw e; } | > > > > > < < < < < | 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 | size_t length = self.length; of_unichar_t *buffer; buffer = of_malloc(length, sizeof(of_unichar_t)); @try { [self getCharacters: buffer inRange: of_range(0, length)]; return [OFData dataWithItemsNoCopy: buffer count: length itemSize: sizeof(of_unichar_t) freeWhenDone: true].items; } @catch (id e) { free(buffer); @throw e; } } - (const of_char16_t *)UTF16String { return [self UTF16StringWithByteOrder: OF_BYTE_ORDER_NATIVE]; } |
︙ | ︙ | |||
2564 2565 2566 2567 2568 2569 2570 | buffer = of_realloc(buffer, j + 1, sizeof(of_char16_t)); } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } objc_autoreleasePoolPop(pool); | > | | | | > > > > | 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 | buffer = of_realloc(buffer, j + 1, sizeof(of_char16_t)); } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } objc_autoreleasePoolPop(pool); @try { return [OFData dataWithItemsNoCopy: buffer count: j + 1 itemSize: sizeof(of_char16_t) freeWhenDone: true].items; } @catch (id e) { free(buffer); @throw e; } } - (size_t)UTF16StringLength { const of_unichar_t *characters = self.characters; size_t length, UTF16StringLength; |
︙ | ︙ | |||
2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 | of_char32_t *buffer; buffer = of_malloc(length + 1, sizeof(of_char32_t)); @try { [self getCharacters: buffer inRange: of_range(0, length)]; buffer[length] = 0; } @catch (id e) { free(buffer); @throw e; } | > > > > > > > > > < < < < < < < < < | 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 | of_char32_t *buffer; buffer = of_malloc(length + 1, sizeof(of_char32_t)); @try { [self getCharacters: buffer inRange: of_range(0, length)]; buffer[length] = 0; if (byteOrder != OF_BYTE_ORDER_NATIVE) for (size_t i = 0; i < length; i++) buffer[i] = OF_BSWAP32(buffer[i]); return [OFData dataWithItemsNoCopy: buffer count: length + 1 itemSize: sizeof(of_char32_t) freeWhenDone: true].items; } @catch (id e) { free(buffer); @throw e; } } - (OFData *)dataWithEncoding: (of_string_encoding_t)encoding { void *pool = objc_autoreleasePoolPush(); OFData *data = [OFData dataWithItems: [self cStringWithEncoding: encoding] |
︙ | ︙ |