[comp.lang.c] Can't type ten steenking lines without a glaring bug...

bhoughto@nevin.intel.com (Blair P. Houghton) (04/05/91)

In article <3661@inews.intel.com> bhoughto@hopi.intel.com (Blair P. Houghton, simpering, compiler-wastrel, code-anal weenie) writes:
>	stat( "filename", &stb );
>	buf = (char *) malloc ( stb.st_size * (sizeof (char *)) );
>	fp = fopen( "filename", "r");
>	fread( buf, stb.st_size, 1, fp );	/* yippee! */

Of course, the second line above should be

	buf = (char *) malloc ( stb.st_size );

				--Blair
				  "I wash colored things in hot
				   water all the time, too..."

john@newave.UUCP (John A. Weeks III) (04/11/91)

In article <3676@inews.intel.com> bhoughto@nevin.intel.com (Blair P. Houghton) writes:
>In article <3661@inews.intel.com> bhoughto@hopi.intel.com (Blair P. Houghton, simpering, compiler-wastrel, code-anal weenie) writes:
>>	buf = (char *) malloc ( stb.st_size * (sizeof (char *)) );

>Of course, the second line above should be

>	buf = (char *) malloc ( stb.st_size );

At least the buffer size was as big as or bigger than expected,
rather than smaller.  Buffer that are too small make running 
programs rather interesting....  8-)

-john-

-- 
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
John A. Weeks III               (612) 942-6969             john@newave.mn.org
NeWave Communications                       ...uunet!tcnet!wd0gol!newave!john