Comments (9)
It should work like this.
from cjson.
Do you mean the case where sizeof(int)!=4 ?
In the 16bit case, the buffered output length will be limited to 32k; unprebuffered output ought to work fine, but that's a bigger issue, and concerns the usage of int throughout the code, and isn't limited to just pow2gt. So far, no reports of issues with this from embedded users.
In the case of sizeof(int)>4, it means we have a maximal output size of ~2GB which needn't apply. However, I'm not totally convinced this is a major issue for a quick lightweight json library.
I'd like to close this issue and reopen it on first report of it causing a real-world issue.
from cjson.
Is it still guaranteed for 64 bit integers bigger than 2^32 that the output of pow2gt
is at least as big as it's input (I can't do the bit fiddling in my head right now)?
If not, there is a heap buffer overflow in the memcpy
in ensure
.
from cjson.
And for systems with 16 bit integers this causes undefined behavior (right shifting by 16).
from cjson.
Is it still guaranteed for 64 bit integers bigger than 2^32 that the output of pow2gt is at least as big as it's input (I can't do the bit fiddling in my head right now)?
- Yes.
And for systems with 16 bit integers this causes undefined behavior (right shifting by 16).
- Compiler will emit a warning, which should abort compile.
from cjson.
What about something like this:
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
#if INT_MAX > 65536UL
x |= x >> 16;
#endif
#if INT_MAX > 4294967296UL
x |= x >> 32;
#endif
from cjson.
I need to check whether INT_MAX gets defined as 32767 rather than 65536, but in principle, something like that, yes... but moreover I'll have a trace through the code for anywhere else that might fail.
Um.. at the risk of asking an off-topic question, could I ask why it is that you're prepared to invest so much time in maintaining cJSON? In practical terms, it's inferior in every metric to RapidJSON...?
from cjson.
RapidJSON didn't exist yet when I started using cJSON and RapidJSON is written in C++, not C.
from cjson.
Awesome :D Good work! :D 👍
from cjson.
Related Issues (20)
- Can't link from CMake HOT 1
- Installing with CMake's FetchContent creates problems with header files
- CMake ≥ 3.13 - Policy CMP0077 (option() behavior)
- decode_pointer_inplace is not working as it should
- Strange behavior observed in cJSON_ReplaceItemInArray HOT 1
- const-qualify cJSON * in cJSON_PrintPreallocated
- Configuring allocators when using FreeRTOS? HOT 1
- Inconsistent error in cJSON_AddItemReferenceToObject
- question on vxworks 6.8 HOT 3
- cJSON_DeleteItemFromArray considers dicts and arrays equally HOT 1
- Cannot Parse JSON HOT 5
- Add a function cJSON_IsEmpty() HOT 4
- JSON Parse Error HOT 11
- Always provide valuestring
- Double Free Vulnerability Discovered in cJSON_Delete Function Through Fuzzing HOT 6
- Fix cmake export to allow cross-compilation with sysroot HOT 1
- Regression on double precision in print_number() when fix a clang compile warning
- A segmentation fault in cJSON_SetValuestring HOT 2
- Can't Install it on PI HOT 2
- cJSON_CreateStringArray and NULL items HOT 4
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 cjson.