![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to increase buffer size in Unix | ziabegg | UNIX for Dummies Questions & Answers | 3 | 01-05-2007 12:17 PM |
| buffer cache size | gsr_kashyap | Linux | 0 | 09-06-2006 10:34 PM |
| Pipe Buffer Size | janet | AIX | 0 | 08-29-2006 04:30 AM |
| What is my UDP send/recieve buffer size | nhatch | UNIX for Dummies Questions & Answers | 3 | 01-26-2005 02:52 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Using fread if the buffer size is not known
Hi...
I am trying to read a binary data that have different types of messages of different lengths. I am using fread() but this functions needs the size and count to read the buffer from the file. I think this may cause that the buffer overlaps other messages. Is there an alternative to read from a binary file without specifying the length? |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
fread will read data and place it into arrays that you allocate. The size and nitems tell fread how much space you allocated for it to work with. Without them, the data might overflow your buffer and clobber other data. This is the "buffer overflow" bug that hackers love to see in a program.
Yes, you can use gets(). There is no way to specify a length to gets. If it overflows your buffer, tough. But writing gets() the way it is was a big mistake. And if you use it, you too are making a big mistake. |
||||
| Google The UNIX and Linux Forums |