# Fread seems to have an issue if it's more than around 100 bytes

**URL:** <https://forum.legato.io/t/fread-seems-to-have-an-issue-if-its-more-than-around-100-bytes/3018>\
**Category:** Uncategorized\
**Created:** [February 7, 2018, 6:12pm UTC](https://forum.legato.io/t/fread-seems-to-have-an-issue-if-its-more-than-around-100-bytes/3018 "2018-02-07T18:12:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![EvetsMostel](https://avatars.discourse-cdn.com/v4/letter/e/3ab097/32.png) [@EvetsMostel](https://forum.legato.io/u/EvetsMostel)\
**Post date:** [February 7, 2018, 6:12pm UTC](https://forum.legato.io/t/fread-seems-to-have-an-issue-if-its-more-than-around-100-bytes/3018/1 "2018-02-07T18:12:34Z")

</div>

Using normal file protocol under c++11.

File \* filep = fopen(“filename”, “r”);

if (filep != NULL)  
{  
char buffer[500];  
size\_t size;  
struct stat statBuff;  
int status = stat(“filename”, &statBuff);  
if (status == 0)  
{  
int numRead = 0;  
numRead = fread(buffer, 500, 1, filep);  
}  
fclose(filep);  
//other code.  
}

This crashes during the fread call. If I reduce the size to 100 bytes it mostly passes, but if I reduce it to one byte and put it in a for loop to read one byte over and over until it reaches size, it works just fine and I get all my data. In this case, my file is only 374 bytes, so I know I’m not running off the end of the buffer.

Has anyone else seen this? This is with Legato 7.11 (R7) with a WP76xx system.

---

<div class="post-metadata">

**Author:** ![spastor](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/spastor/32/80_2.png) [@spastor](https://forum.legato.io/u/spastor)\
**Post date:** [February 9, 2018, 8:48am UTC](https://forum.legato.io/t/fread-seems-to-have-an-issue-if-its-more-than-around-100-bytes/3018/2 "2018-02-09T08:48:56Z")

</div>

Your application is sanboxed ?

Please, it’s possible to show your adef file ?

Please, check in the [documentation, the application def: maxFileSystemBytes and maxMemoryBytes](http://legato.io/legato-docs/latest/defFilesAdef.html#defFilesAdef_maxFileSystemBytes).

Best regards,  
Sylvain

---

<div class="post-metadata">

**Author:** ![EvetsMostel](https://avatars.discourse-cdn.com/v4/letter/e/3ab097/32.png) [@EvetsMostel](https://forum.legato.io/u/EvetsMostel)\
**Post date:** [February 9, 2018, 6:19pm UTC](https://forum.legato.io/t/fread-seems-to-have-an-issue-if-its-more-than-around-100-bytes/3018/3 "2018-02-09T18:19:47Z")

</div>

Hi @spastor,  
No, it’s not sandboxed as there are things I can’t do under sandboxed mode. It doesn’t appear to be a memory issue as I can either new, or declare a stack variable to contain the bytes read, and as long as I fread it one byte at a time, then all is well.

Here is the .adef, just standard stuff except that it’s not sandboxed.

sandboxed: false

executables:  
{  
TestProgram = (TestProgramPP)  
}

bindings:  
{  
TestProgram.TestProgramPP.le\_mdc → .le\_mdc  
TestProgram.TestProgramPP.le\_data → .le\_data  
TestProgram.TestProgramPP.le\_info → .le\_info  
TestProgram.TestProgramPP.le\_mrc → .le\_mrc  
TestProgram.TestProgramPP.le\_sim → .le\_sim  
}  
processes:  
{  
envVars:  
{  
LE\_LOG\_LEVEL = DEBUG  
}

run:  
{  
( TestProgram )  
}

maxCoreDumpFileBytes: 512K  
maxFileBytes: 512K  
}

version: 1.0.0  
maxFileSystemBytes: 512K

---

<div class="post-metadata">

**Author:** ![riotc](https://avatars.discourse-cdn.com/v4/letter/r/65b543/32.png) [@riotc](https://forum.legato.io/u/riotc)\
**Post date:** [October 4, 2018, 8:38am UTC](https://forum.legato.io/t/fread-seems-to-have-an-issue-if-its-more-than-around-100-bytes/3018/4 "2018-10-04T08:38:57Z")

</div>

I tried to read more than 100 bytes using fread with release 7 and did not have any issues. Can you post the log if you are still facing this issue?

---

<div class="post-metadata">

**Author:** ![EvetsMostel](https://avatars.discourse-cdn.com/v4/letter/e/3ab097/32.png) [@EvetsMostel](https://forum.legato.io/u/EvetsMostel)\
**Post date:** [October 4, 2018, 2:19pm UTC](https://forum.legato.io/t/fread-seems-to-have-an-issue-if-its-more-than-around-100-bytes/3018/5 "2018-10-04T14:19:40Z")

</div>

This was very early in the release process for the WP76xx, probably R6. I found that the c++ ifstream works, so I’ve moved on.
