Skip to content

Commit 293aad5

Browse files
committed
Use item buffer macros consistently, avoiding excessively large buffers.
1 parent 0dece04 commit 293aad5

5 files changed

Lines changed: 16 additions & 13 deletions

File tree

Source/GSPrivate.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ typedef struct objc_category* Category;
9696
* the array and GS_ENDITEMBUF() to end it. The idea is to ensure that small
9797
* arrays are allocated on the stack (for speed), but large arrays are
9898
* allocated from the heap (to avoid stack overflow).
99+
* The first argument is the name to be used for a pointer to the buffer.
100+
* The second argument is the number of items in the buffer.
101+
* The third argument is the type of the items in the buffer.
102+
* The minimum size of the buffer produced is sufficient to hold one item.
99103
*/
100104
#if __GNUC__ > 3 && !defined(__clang__)
101105
__attribute__((unused)) static void GSFreeTempBuffer(void **b)

Source/GSString.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5207,7 +5207,7 @@ - (void) replaceCharactersInRange: (NSRange)aRange
52075207
*/
52085208
if (_flags.wide)
52095209
{
5210-
GS_BEGINITEMBUF(buf, (length * sizeof(unichar)), unichar);
5210+
GS_BEGINITEMBUF(buf, length, unichar);
52115211

52125212
[aString getCharacters: buf];
52135213
if (offset < 0)
@@ -5224,7 +5224,7 @@ - (void) replaceCharactersInRange: (NSRange)aRange
52245224
}
52255225
else
52265226
{
5227-
GS_BEGINITEMBUF(buf, ((length+1) * sizeof(char)), char);
5227+
GS_BEGINITEMBUF(buf, (length+1), char);
52285228

52295229
[aString getCString: buf
52305230
maxLength: length+1

Source/NSNumberFormatter.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1457,7 +1457,7 @@ - (NSNumber *) numberFromString: (NSString *)string
14571457
UErrorCode err = U_ZERO_ERROR;
14581458
int64_t intNum;
14591459
double doubleNum;
1460-
GS_BEGINITEMBUF(ustring, length * sizeof(unichar), unichar)
1460+
GS_BEGINITEMBUF(ustring, length, unichar)
14611461

14621462
[string getCharacters: ustring range: NSMakeRange(0, length)];
14631463

Source/NSPropertyList.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1596,7 +1596,7 @@ static id parsePlItem(pldata* pld) NS_RETURNS_RETAINED
15961596
unsigned char *ptr;
15971597
int base = [output length];
15981598
int len = 0;
1599-
GS_BEGINITEMBUF(ustring, (length * sizeof(unichar)), unichar)
1599+
GS_BEGINITEMBUF(ustring, length, unichar)
16001600

16011601
end = &ustring[length];
16021602
[obj getCharacters: ustring];

Source/NSString.m

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2669,8 +2669,7 @@ - (NSRange) rangeOfString: (NSString *)aString
26692669

26702670
/* Range to search is bigger than string to look for.
26712671
*/
2672-
GS_BEGINITEMBUF2(charsSelf, (searchRange.length*sizeof(unichar)),
2673-
unichar)
2672+
GS_BEGINITEMBUF2(charsSelf, searchRange.length, unichar)
26742673
[self getCharacters: charsSelf range: searchRange];
26752674
end = searchRange.length;
26762675
if ((mask & NSCaseInsensitiveSearch) == NSCaseInsensitiveSearch)
@@ -2763,7 +2762,7 @@ - (NSRange) rangeOfString: (NSString *)aString
27632762
}
27642763
else
27652764
{
2766-
GS_BEGINITEMBUF(charsOther, (countOther*sizeof(unichar)), unichar)
2765+
GS_BEGINITEMBUF(charsOther, countOther, unichar)
27672766

27682767
[aString getCharacters: charsOther range: NSMakeRange(0, countOther)];
27692768
if (YES == insensitive)
@@ -2782,7 +2781,7 @@ - (NSRange) rangeOfString: (NSString *)aString
27822781
{
27832782
/* Range to search is same size as string to look for.
27842783
*/
2785-
GS_BEGINITEMBUF2(charsSelf, (countOther*sizeof(unichar)), unichar)
2784+
GS_BEGINITEMBUF2(charsSelf, countOther, unichar)
27862785
if ((mask & NSBackwardsSearch) == NSBackwardsSearch)
27872786
{
27882787
searchRange.location = NSMaxRange(searchRange) - countOther;
@@ -2843,8 +2842,7 @@ - (NSRange) rangeOfString: (NSString *)aString
28432842
}
28442843
/* Range to search is bigger than string to look for.
28452844
*/
2846-
GS_BEGINITEMBUF2(charsSelf, (searchRange.length*sizeof(unichar)),
2847-
unichar)
2845+
GS_BEGINITEMBUF2(charsSelf, searchRange.length, unichar)
28482846
[self getCharacters: charsSelf range: searchRange];
28492847

28502848
if (YES == insensitive)
@@ -2955,8 +2953,8 @@ - (NSRange) rangeOfString: (NSString *)aString
29552953
UErrorCode status = U_ZERO_ERROR;
29562954
NSUInteger countSelf = searchRange.length;
29572955
UStringSearch *search = NULL;
2958-
GS_BEGINITEMBUF(charsSelf, (countSelf * sizeof(unichar)), unichar)
2959-
GS_BEGINITEMBUF2(charsOther, (countOther * sizeof(unichar)), unichar)
2956+
GS_BEGINITEMBUF(charsSelf, countSelf, unichar)
2957+
GS_BEGINITEMBUF2(charsOther, countOther, unichar)
29602958

29612959
// Copy to buffer
29622960

@@ -4875,7 +4873,8 @@ - (NSString*) stringByDeletingLastPathComponent
48754873
unichar *to;
48764874
unsigned o;
48774875
unsigned lastComponent = root;
4878-
GS_BEGINITEMBUF(from, (end * 2 * sizeof(unichar)), unichar)
4876+
unsigned space = end * 2; // from and to in same buffer
4877+
GS_BEGINITEMBUF(from, space, unichar)
48794878

48804879
to = from + end;
48814880
[self getCharacters: from range: NSMakeRange(0, end)];

0 commit comments

Comments
 (0)