Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot add more than 11 objects. Is this a known issue? #599

Closed
JoergSchneiderSimon opened this issue May 9, 2020 · 9 comments
Closed

Comments

@JoergSchneiderSimon
Copy link

Created this PoC code to replicate an issue I am seeing in my production code.
as of

45b6416 (HEAD -> master, origin/master, origin/HEAD) Merge branch 'master' of https://github.com/json-c/json-c
It never adds more than 11 objects.

#include <stdio.h>
#include "json.h"

int main() {
int i=1;
char object[10214];
/Creating a json object/
json_object *jobj = json_object_new_object();
for(i=1; i <100; i++){
snprintf(object, 1024, "OBJECT_%d", i);
json_object_object_add(jobj, object, json_object_new_int(i));
printf("Round %d:\r\n", i);
printf("%s\r\n\r\n", json_object_to_json_string(jobj));
}
return 0;
}

I get:

Round 1:
{ "OBJECT_1": 1 }

Round 2:
{ "OBJECT_1": 1, "OBJECT_2": 2 }

Round 3:
{ "OBJECT_1": 1, "OBJECT_2": 2, "OBJECT_3": 3 }

Round 4:
{ "OBJECT_1": 1, "OBJECT_2": 2, "OBJECT_3": 3, "OBJECT_4": 4 }

.......

Round 10:
{ "OBJECT_1": 1, "OBJECT_2": 2, "OBJECT_3": 3, "OBJECT_4": 4, "OBJECT_5": 5, "OBJECT_6": 6, "OBJECT_7": 7, "OBJECT_8": 8, "OBJECT_9": 9, "OBJECT_10": 10 }

Round 11:
{ "OBJECT_1": 1, "OBJECT_2": 2, "OBJECT_3": 3, "OBJECT_4": 4, "OBJECT_5": 5, "OBJECT_6": 6, "OBJECT_7": 7, "OBJECT_8": 8, "OBJECT_9": 9, "OBJECT_10": 10, "OBJECT_11": 11 }

Round 12:
{ "OBJECT_1": 1, "OBJECT_2": 2, "OBJECT_3": 3, "OBJECT_4": 4, "OBJECT_5": 5, "OBJECT_6": 6, "OBJECT_7": 7, "OBJECT_8": 8, "OBJECT_9": 9, "OBJECT_10": 10, "OBJECT_11": 11 }

Round 13:
{ "OBJECT_1": 1, "OBJECT_2": 2, "OBJECT_3": 3, "OBJECT_4": 4, "OBJECT_5": 5, "OBJECT_6": 6, "OBJECT_7": 7, "OBJECT_8": 8, "OBJECT_9": 9, "OBJECT_10": 10, "OBJECT_11": 11 }

........

Round 98:
{ "OBJECT_1": 1, "OBJECT_2": 2, "OBJECT_3": 3, "OBJECT_4": 4, "OBJECT_5": 5, "OBJECT_6": 6, "OBJECT_7": 7, "OBJECT_8": 8, "OBJECT_9": 9, "OBJECT_10": 10, "OBJECT_11": 11 }

Round 99:
{ "OBJECT_1": 1, "OBJECT_2": 2, "OBJECT_3": 3, "OBJECT_4": 4, "OBJECT_5": 5, "OBJECT_6": 6, "OBJECT_7": 7, "OBJECT_8": 8, "OBJECT_9": 9, "OBJECT_10": 10, "OBJECT_11": 11 }

@JoergSchneiderSimon
Copy link
Author

Issue exists in 0.14 but NOT in 0.13.1

@JoergSchneiderSimon
Copy link
Author

commit 22870ac introduces the issue

@hawicz
Copy link
Member

hawicz commented May 10, 2020

That's pretty bizarre that simply building static libs would cause this problem. I can confirm that I see the same output you do. Investigating...

@hawicz
Copy link
Member

hawicz commented May 10, 2020

77d935b works
d07b910 fails
The failing commit was from PR#592.

@stoeckmann, looks like we missed something in the logic of your changes.

@hawicz
Copy link
Member

hawicz commented May 10, 2020

Found it, condition on line 585 of linkhash.c is backwards:

int new_size = INT_MAX / 2 < t->size ? t->size * 2 : INT_MAX;

I'll be pushing a fix shortly.

hawicz added a commit that referenced this issue May 10, 2020
…was preventing adding more than 11 objects.

Add a test to check for this too.
@hawicz hawicz closed this as completed May 10, 2020
@JoergSchneiderSimon
Copy link
Author

Thank you Eric!

@stoeckmann
Copy link
Contributor

Yes, thank you for figuring out and applying a patch directly!

besser82 pushed a commit to besser82/json-c that referenced this issue May 10, 2020
… that was preventing adding more than 11 objects.

Add a test to check for this too.
@ddstreet
Copy link

BTW that ^ commit doesn't fix it, the problem isn't ordering. See #610

@hawicz
Copy link
Member

hawicz commented May 16, 2020

TL;DR for #610: As @besser82 explained, commit 519dfe1 does fix the problem: "If INT_MAX / 2 is smaller than t->size, it would resize to double t->size, otherwise resize to INT_MAX."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants