Skip to content

Commit

Permalink
json: fix array element deletion
Browse files Browse the repository at this point in the history
OpenSIPS incorrectly calls the JSON-C array element deletion function by passing the size of the array instead of the desired count of elements to delete. When attempting to delete from index `0`, it results in the deletion of all elements, while specifying an index greater than `0` leads to no deletion due to overindexing.

### Example 1:
```
  $json(obj) := "[ 1, 2, 3 ]";
  $json(obj[0]) = NULL;
  xlog("$json(obj)\n");
```
Result:   `[]`
Expected: `[ 2, 3 ]`

### Example 2:
```
  $json(obj) := "[ 1, 2, 3 ]";
  $json(obj[1]) = NULL;
  xlog("$json(obj)\n");
```
Result:   `[ 1, 2, 3 ]`
Expected: `[ 1, 3 ]`
  • Loading branch information
benceszigeti committed Nov 10, 2023
1 parent b56acff commit d53e6f3
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions modules/json/array_del.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
void json_object_array_del(struct json_object* obj, int idx)
{
#if JSON_C_VERSION_NUM >= JSON_C_VERSION_013
array_list_del_idx(json_object_get_array(obj), idx,
json_object_get_array(obj)->length);
array_list_del_idx(json_object_get_array(obj), idx, 1);
#else
if(idx >= obj->o.c_array->length)
return;
Expand Down

0 comments on commit d53e6f3

Please sign in to comment.