ObjFW  Check-in [04bb18457a]

Overview
Comment:Set errno to 0 before calling strto*

It is not guaranteed that errno is set to 0 when there is no
overflow/underflow, so it needs to be set to 0 before, in case it
already is ERANGE from a previous call.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 04bb18457a87d3d890ffd7f808432b4ea9eb326a2f46ff2da6e61ab168ac49d5
User & Date: js on 2020-08-13 19:43:33
Other Links: manifest | tags
Context
2020-08-13
19:49
Work around amiga-gcc missing strto(u)ll check-in: 138410a925 user: js tags: trunk
19:43
Set errno to 0 before calling strto* check-in: 04bb18457a user: js tags: trunk
19:27
Always cast argument to isspace() to unsigned char check-in: ce5dfd4a83 user: js tags: trunk
Changes

Modified src/OFString.m from [fbf885bed7] to [3a36a1ae89].

2322
2323
2324
2325
2326
2327
2328

2329
2330
2331
2332
2333
2334
2335
- (long long)longLongValueWithBase: (int)base
{
	void *pool = objc_autoreleasePoolPush();
	const char *UTF8String = self.UTF8String;
	char *endPointer = NULL;
	long long value;


	value = strtoll(UTF8String, &endPointer, base);

	if ((value == LLONG_MIN || value == LLONG_MAX) && errno == ERANGE)
		@throw [OFOutOfRangeException exception];

	/* Check if there are any invalid chars left */
	if (endPointer != NULL)







>







2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
- (long long)longLongValueWithBase: (int)base
{
	void *pool = objc_autoreleasePoolPush();
	const char *UTF8String = self.UTF8String;
	char *endPointer = NULL;
	long long value;

	errno = 0;
	value = strtoll(UTF8String, &endPointer, base);

	if ((value == LLONG_MIN || value == LLONG_MAX) && errno == ERANGE)
		@throw [OFOutOfRangeException exception];

	/* Check if there are any invalid chars left */
	if (endPointer != NULL)
2358
2359
2360
2361
2362
2363
2364

2365
2366
2367
2368
2369
2370
2371
	/* Use isspace since strtoull uses the same. */
	while (isspace((unsigned char)*UTF8String))
		UTF8String++;

	if (*UTF8String == '-')
		@throw [OFInvalidFormatException exception];


	value = strtoull(UTF8String, &endPointer, base);

	if (value == ULLONG_MAX && errno == ERANGE)
		@throw [OFOutOfRangeException exception];

	/* Check if there are any invalid chars left */
	if (endPointer != NULL)







>







2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
	/* Use isspace since strtoull uses the same. */
	while (isspace((unsigned char)*UTF8String))
		UTF8String++;

	if (*UTF8String == '-')
		@throw [OFInvalidFormatException exception];

	errno = 0;
	value = strtoull(UTF8String, &endPointer, base);

	if (value == ULLONG_MAX && errno == ERANGE)
		@throw [OFOutOfRangeException exception];

	/* Check if there are any invalid chars left */
	if (endPointer != NULL)
2402
2403
2404
2405
2406
2407
2408

2409
2410
2411
2412
2413
2414
2415
	const char *UTF8String = [self
	    stringByReplacingOccurrencesOfString: @"."
				      withString: decimalPoint].UTF8String;
#endif
	char *endPointer = NULL;
	float value;


#ifdef HAVE_STRTOF_L
	value = strtof_l(UTF8String, &endPointer, cLocale);
#else
	value = strtof(UTF8String, &endPointer);
#endif

	if (value == HUGE_VALF)







>







2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
	const char *UTF8String = [self
	    stringByReplacingOccurrencesOfString: @"."
				      withString: decimalPoint].UTF8String;
#endif
	char *endPointer = NULL;
	float value;

	errno = 0;
#ifdef HAVE_STRTOF_L
	value = strtof_l(UTF8String, &endPointer, cLocale);
#else
	value = strtof(UTF8String, &endPointer);
#endif

	if (value == HUGE_VALF)
2450
2451
2452
2453
2454
2455
2456

2457
2458
2459
2460
2461
2462
2463
	const char *UTF8String = [self
	    stringByReplacingOccurrencesOfString: @"."
				      withString: decimalPoint].UTF8String;
#endif
	char *endPointer = NULL;
	double value;


#ifdef HAVE_STRTOD_L
	value = strtod_l(UTF8String, &endPointer, cLocale);
#else
	value = strtod(UTF8String, &endPointer);
#endif

	if (value == HUGE_VAL)







>







2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
	const char *UTF8String = [self
	    stringByReplacingOccurrencesOfString: @"."
				      withString: decimalPoint].UTF8String;
#endif
	char *endPointer = NULL;
	double value;

	errno = 0;
#ifdef HAVE_STRTOD_L
	value = strtod_l(UTF8String, &endPointer, cLocale);
#else
	value = strtod(UTF8String, &endPointer);
#endif

	if (value == HUGE_VAL)