SIZE_T_MAX (Re: More fwrite limits)

Karl Heuer karl at haddock.ima.isc.com
Mon Jul 9 06:01:05 AEST 1990


In article <Fq7k90?@cs.psu.edu> flee at guardian.cs.psu.edu (Felix Lee) writes:
>Here are some innocuous statements that can run into trouble...

To test whether (expr <= SIZE_T_MAX), where (expr) is unsigned long int, use
(expr == (unsigned long int)(size_t)expr).  In your example,
	unsigned long int sz = 1UL + strlen(a) + strlen(b);
	s = (sz != (unsigned long int)(size_t)sz ? NULL : malloc((size_t)sz));

Karl W. Z. Heuer (karl at kelp.ima.isc.com or ima!kelp!karl), The Walking Lint



More information about the Comp.std.c mailing list