Comments (6)
// Stores number of files in the child directory
len_preview = getNumberofFiles(next_dir);
// Stores files in the child directory
char* next_directories[len_preview];
status = getFiles(next_dir, next_directories);
if status == -1:
continue;
Will the status check solve this problem?
from cfiles.
No, it will blow out your call stack. Call stack is meant for small and relatively fixed-sized arrays.
For your cases, I think the best approach is to allocate it on heap.
FYI, I use my Stensal SDK (https://stensal.com) to build and test your code, and found this problem.
from cfiles.
If I use malloc
, the code will look like this:
// Stores number of files in the child directory
len_preview = getNumberofFiles(next_dir);
// Stores files in the child directory
char** next_directories;
next_directories = (char **)malloc(len_preview * sizeof(char *));
/*
Rest of the code goes here
*/
// Free Memory
for( i=0; i<len_preview; i++ )
{
free(next_directories[i]);
}
free(next_directories);
So will this be enough?
Also I have used a similar declaration for char *directories[len];
. So why is it the case that it is not wrong? Should I use malloc
in that case too?
from cfiles.
I only see the allocation for next_directories. Presumabily you also allocate for each of next_directories[i]. If it is the case, yes, it's more reliable than allocating on call stacks.
It's not about right or wrong. It's less reliable and you can exhaust call stack quickly. The limit of call stack is much smaller than the limit of heap.
from cfiles.
I made the relevant changes in the latest commit 9be9889.
Let me know if this is good enough for closing this issue. Thanks!
from cfiles.
See #11
from cfiles.
Related Issues (20)
- Bug with preview HOT 2
- Can't preview image. HOT 3
- Build fails on powerpc 32 bit: 'for' loop initial declaration used outside C99 mode HOT 2
- Error with preview. HOT 2
- Strange behavior opening bash scripts (xdg-open, vim) HOT 17
- Can you add a keybind to create a new folder/file HOT 1
- Auto-reload
- Enhancement: add a help tabble for shortcuts.
- Enhancement: Add a toggle to turn off file preview
- enhancement HOT 1
- Enhancement: copy a file into the same folder
- Enhancement: separate keys to go to next folder and open a file
- error previewing lost+found and root directory
- Preview window/process left open after exit
- BUG Consume all the RAM memory
- Unable to delete folder with same name of a file in trash
- Don't preview zip file after preview pdf
- Images off center on ST terminal HOT 1
- Support transparency
- Crash while move with KEY_UP and KEY_DOWN
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cfiles.