Overflow checks #6681
Replies: 1 comment
-
Posted at 2023-02-01 by @gfwilliams I'm not sure I understand - where in _jswrap_interface_setTimeoutOrInterval do you see a problem? And where is the issue in Realistically in Espruino arrays of JsVars are extremely rare and it's pretty easy to see that everything is in range, so I wouldn't bother with overflow checking. What is important is checking your locks/unlocks all match but there's no real way to check that short of running your code and checking for memory leaks Posted at 2023-02-01 by @fanoush @!evil Just to make sure, by "overflow" you always mean "out of memory"? Posted at 2023-02-01 by !evil Sorry for the confusion, i meant "out of memory", not out of array bounds. I hope the following is better. In Regarding The main question is: care about "out of memory" (e.g. Posted at 2023-02-01 by @gfwilliams Ahh, right - that makes a lot more sense! Thanks for that - in
It's definitely good practice to check when allocating something like an object but I wouldn't worry about trying to clean up after yourself in the library. When you do 'SetChildAndUnLock(.... jsvNew...)` then memory errors really don't matter at all. Espruino should continue working just fine after an out of memory error - and actually the Linux build does have a 'memtest' where it'll just run the tests time after time, slowly decreasing memory so that it can see if anything breaks badly when out of memory happens at different times. If a lock is 'leaked' it's not the end of the world. It basically just means that var can't be garbage collected, so it might result in a memory leak - but in many cases it probably won't even be noticed. Posted at 2023-02-01 by !evil
This is very reassuring :) Thanks for the guidance! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2023-01-31 by !evil
Hi,
I was wondering what the recommended approach to memory overflow is. Most of
jsvar.c
check for overflow and behave accordingly, while other code assume no overflow, e.g._jswrap_interface_setTimeoutOrInterval
. Then there isjsvObjectSetChildAndUnLock
which doesn't unlock the child in case of overflow, while others likejsvArrayPushAndUnLock
do.I tried to use the following defines for perfect overflow coverage in my library
but I'm uncertain if its worth the trouble. What if I won't check for overflow, like
_jswrap_interface_setTimeoutOrInterval
, would it lead to unexpected behavior in case of overflow instead of noisy "segfault"?Beta Was this translation helpful? Give feedback.
All reactions