ObjFW  Check-in [439216041b]

Overview
Comment:Don't use alloca, as it could be unsafe.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 439216041bc60a569a00d3f4c96a1e575ddd8f654bbba5049ca6d7686c9b40b8
User & Date: js on 2012-02-28 14:29:32
Other Links: manifest | tags
Context
2012-02-28
16:20
Update PLATFORMS. check-in: 3b618415fb user: js tags: trunk
14:29
Don't use alloca, as it could be unsafe. check-in: 439216041b user: js tags: trunk
14:28
Make it more clear that +[pluginFromFile:] does not return OFPlugin*. check-in: 0727c9266b user: js tags: trunk
Changes

Modified src/OFProcess.m from [be6e10ea82] to [39656659f7].

85
86
87
88
89
90
91
92



93
94
95
96
97
98
99
			@throw [OFInitializationFailedException
			    exceptionWithClass: isa];

		switch ((pid = fork())) {
		case 0:;
			OFString **cArray = [arguments cArray];
			size_t i, count = [arguments count];
			char **argv = alloca((count + 2) * sizeof(char*));




			argv[0] = (char*)[programName cStringWithEncoding:
			    OF_STRING_ENCODING_NATIVE];

			for (i = 0; i < count; i++)
				argv[i + 1] = (char*)[cArray[i]
				    cStringWithEncoding:







|
>
>
>







85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
			@throw [OFInitializationFailedException
			    exceptionWithClass: isa];

		switch ((pid = fork())) {
		case 0:;
			OFString **cArray = [arguments cArray];
			size_t i, count = [arguments count];
			char **argv;

			argv = [self allocMemoryForNItems: count + 2
						   ofSize: sizeof(char*)];

			argv[0] = (char*)[programName cStringWithEncoding:
			    OF_STRING_ENCODING_NATIVE];

			for (i = 0; i < count; i++)
				argv[i + 1] = (char*)[cArray[i]
				    cStringWithEncoding:

Modified src/OFString.m from [eb65ec8863] to [f2bf50723c].

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

#include <stdarg.h>
#include <stdlib.h>
#include <string.h>

#include <sys/stat.h>

#ifdef _WIN32
# include <malloc.h>
#endif

#import "OFString.h"
#import "OFString_UTF8.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFFile.h"
#import "OFURL.h"
#import "OFHTTPRequest.h"







<
<
<
<







18
19
20
21
22
23
24




25
26
27
28
29
30
31

#include <stdarg.h>
#include <stdlib.h>
#include <string.h>

#include <sys/stat.h>





#import "OFString.h"
#import "OFString_UTF8.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFFile.h"
#import "OFURL.h"
#import "OFHTTPRequest.h"
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482

1483



1484
1485
1486
1487
1488
1489
1490
1491
1492
1493



1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510

1511



1512
1513

1514
1515
1516
1517
1518
1519
1520
1521



1522
1523
1524
1525
1526
1527
1528
	[new makeImmutable];

	return new;
}

- (BOOL)hasPrefix: (OFString*)prefix
{
	OFAutoreleasePool *pool;
	of_unichar_t *tmp;
	const of_unichar_t *prefixString;
	size_t prefixLength;
	int compare;

	if ((prefixLength = [prefix length]) > [self length])
		return NO;


	tmp = alloca(prefixLength * sizeof(of_unichar_t));



	[self getCharacters: tmp
		    inRange: of_range(0, prefixLength)];

	pool = [[OFAutoreleasePool alloc] init];

	prefixString = [prefix unicodeString];
	compare = memcmp(tmp, prefixString,
	    prefixLength * sizeof(of_unichar_t));

	[pool release];




	return !compare;
}

- (BOOL)hasSuffix: (OFString*)suffix
{
	OFAutoreleasePool *pool;
	of_unichar_t *tmp;
	const of_unichar_t *suffixString;
	size_t length, suffixLength;
	int compare;

	if ((suffixLength = [suffix length]) > [self length])
		return NO;

	length = [self length];


	tmp = alloca(suffixLength * sizeof(of_unichar_t));



	[self getCharacters: tmp
		    inRange: of_range(length - suffixLength, suffixLength)];


	pool = [[OFAutoreleasePool alloc] init];

	suffixString = [suffix unicodeString];
	compare = memcmp(tmp, suffixString,
	    suffixLength * sizeof(of_unichar_t));

	[pool release];




	return !compare;
}

- (OFArray*)componentsSeparatedByString: (OFString*)delimiter
{
	return [self componentsSeparatedByString: delimiter







<








>
|
>
>
>
|
|

|

|
|
|

|
>
>
>






<










>
|
>
>
>
|
|
>

|

|
|
|

|
>
>
>







1463
1464
1465
1466
1467
1468
1469

1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501

1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
	[new makeImmutable];

	return new;
}

- (BOOL)hasPrefix: (OFString*)prefix
{

	of_unichar_t *tmp;
	const of_unichar_t *prefixString;
	size_t prefixLength;
	int compare;

	if ((prefixLength = [prefix length]) > [self length])
		return NO;

	tmp = [self allocMemoryForNItems: prefixLength
				  ofSize: sizeof(of_unichar_t)];
	@try {
		OFAutoreleasePool *pool;

		[self getCharacters: tmp
			    inRange: of_range(0, prefixLength)];

		pool = [[OFAutoreleasePool alloc] init];

		prefixString = [prefix unicodeString];
		compare = memcmp(tmp, prefixString,
		    prefixLength * sizeof(of_unichar_t));

		[pool release];
	} @finally {
		[self freeMemory: tmp];
	}

	return !compare;
}

- (BOOL)hasSuffix: (OFString*)suffix
{

	of_unichar_t *tmp;
	const of_unichar_t *suffixString;
	size_t length, suffixLength;
	int compare;

	if ((suffixLength = [suffix length]) > [self length])
		return NO;

	length = [self length];

	tmp = [self allocMemoryForNItems: suffixLength
				  ofSize: sizeof(of_unichar_t)];
	@try {
		OFAutoreleasePool *pool;

		[self getCharacters: tmp
			    inRange: of_range(length - suffixLength,
					 suffixLength)];

		pool = [[OFAutoreleasePool alloc] init];

		suffixString = [suffix unicodeString];
		compare = memcmp(tmp, suffixString,
		    suffixLength * sizeof(of_unichar_t));

		[pool release];
	} @finally {
		[self freeMemory: tmp];
	}

	return !compare;
}

- (OFArray*)componentsSeparatedByString: (OFString*)delimiter
{
	return [self componentsSeparatedByString: delimiter