paragon.john@[EMAIL PROTECTED]
wrote:
>
> I am trying to read a file into some allocated memory as part of a
> program and I am running into a problem. The program gets a
> segmentation fault during fread. I have previously used this code on
> 64-bit RHEL4 without any problems but I am not having this issue on 32-
> bit RHEL5. I have simplified the code to it's most basic form and I
> am still seeing the issue. Below is a full program that causes the
> error. If anybody knows what may be causing the problem, help would
> be greatly appreciated....
>
> #include <stdio.h>
> #include <fcntl.h>
There is no such header file in standard C.
>
> int main()
Better would be "int main(void)
> {
> int data_size = 1024*1024;
There is no guarantee that an int can hold this number. Use a
long, or possibly a size_t.
> u_char *data_buf;
There is no such type as u_char.
> FILE *data_file;
> int data_num;
>
> data_buf = (unsigned char *) valloc(data_size);
There is no such function as valloc. If you meant malloc, don't
cast the result, which hides the error of failing to "#include
<stdlib.h>". The size parameter should be a size_t type.
> printf("Memory allocated.\n");
How do you know?
> data_file = fopen("data_file","rb");
> printf("File opened.");
How do you know?
> data_num = fread(data_buf, sizeof(u_char), data_size, data_file);
> printf("File read.");
How do you know?
> return 0;
> }
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
** Posted from http://www.teranews.com
**


|