Comments (3)
So I've been looking over this and adding in a few checks
- Functions that return arrays just need a check to see if
malloc
failed, returningnullptr
if it did - Functions that return 2D arrays need the same check for the top-level array, as well as checks for each sub-arrays. If an allocation of a sub-array fails, either all the entries before the current one can be freed and
nullptr
returned, or that entry set tonullptr
. Freeing everything and returningnullptr
seems to assume less about the caller, though, and I think this is the safest behavior.
Things get a little bit hairy with the ConvertToC
functions with checks, because then a struct could be partially initialized without knowing so. Example:
static void ConvertToC(const EntryInfo& in, NT_EntryInfo* out) {
// Returning early here possibly leaves `out` completely uninitialized,
// but the caller doesn't know
if (!out) return false;
out->entry = in.entry;
// out->name could be uninitialized here, but we don't know
// and can't propagate that error up to the caller
ConvertToC(in.name, &out->name);
out->type = in.type;
out->flags = in.flags;
out->last_change = in.last_change;
}
Since ConvertToC
is a private interface, it is possible to propagate error information, but then you have the same problem when you get to the public interfaces; NT_GetEntryValue
, for example, has no way to tell the caller that there was an allocation error other than leaving the value marked as unassigned. Doing that, though, would cause ambiguity between an OOM error and a nonexistent entry.
At the very least, the undefined behavior should be eliminated, and this could be done by just aborting the process if an alloc failed.
from ntcore.
Frankly, out of memory errors are seldom recoverable. Simply aborting on allocation failure is probably the right answer.
from ntcore.
Yeah, that seems like the most consistent thing to do. I'll submit a PR in a bit.
from ntcore.
Related Issues (20)
- Get 32-bit JVM builds working
- wait for notifier queue to clear HOT 10
- Cannot build with cmake anymore HOT 29
- Error when Gradle Building ntcore HOT 11
- entry instance handles are completely invalid when a name is deleted
- Potential issues when deleting entries HOT 1
- Fix Travis CI building ntcore HOT 15
- DeleteAllEntries subtle bug HOT 1
- LoadEntries flag bug
- SendableChooser change listener no longer (easily) exists HOT 1
- What to do after publishing in Maven locally? HOT 2
- segfault in OutlineViewer.jar HOT 6
- Can't build on raspian HOT 2
- Describe potential synchronization scenarios and desired results HOT 1
- Cannot use C interface with gcc HOT 6
- NetworkTables writes hang if flush is used more often than the update rate
- NetworkTableEntry.callRpc is package-private HOT 1
- Build Failing on TX1 aarch64 HOT 1
- Error compiling ntcore for windows x64 HOT 1
- NetworkTables Desktop Client and WPILib Desktop Simulation HOT 1
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 ntcore.